whitecube / nova-flexible-content

Flexible Content & Repeater Fields for Laravel Nova
MIT License
788 stars 228 forks source link

Adding new rows through.. code? #375

Closed HeadStudios closed 2 years ago

HeadStudios commented 2 years ago

Any way to add new repeatable rows through code rather than through the backend? Does that make sense? I want to add a bunch of meta to a Resource through code... I don't know if i'm explaining correctly. (btw I mean like once I have repeatable flexible field setup all ready.. and I want to add 2 rows.. but through code).

Also any luck on the Date casting (this is a secondary issue not a major one).

Hope I explained myself well enough.

Thank you!

HeadStudios commented 2 years ago

Ok this was a bad idea lol

Route::get('/flexible', function() {

$opps = Opps::where('ID', 5)->get();
foreach($opps as $opp) {
    $terms = $opp->terms;
    $terms->push(['headline'=>'This is dynamic', 'description'=>'A dynamic description goes here']);
    $opp->save();
    return 'Just go for it';
}

});

Now that Resource is corrupted :(

https://share.getcloudapp.com/7Ku6GqYj

This also corrupted the resource

$product = collect(['product_name' => 'Dynamic World', 'product_feature' => 'Dynamic Feature', 'product_benefit' => 'Dynamic product benfit']); $opp->products->push($product);

voidgraphics commented 2 years ago

Not planned at the moment, but I suggest you add one manually and then study the structure that gets saved in the database — it's not as simple as what you tried, you also need to specify the layout type and a unique identifier for it.

HeadStudios commented 2 years ago

Not planned at the moment, but I suggest you add one manually and then study the structure that gets saved in the database — it's not as simple as what you tried, you also need to specify the layout type and a unique identifier for it.

Thank you!! Good idea to check the DB and go from there. APpreciate it.