Open tongtastic opened 4 years ago
Hi there, sounds like a bug to me! Thanks for reporting.
Since Laravel Nova 3.4.0 there is a default method, see: https://github.com/laravel/nova/pull/866 and the docs: https://nova.laravel.com/docs/3.0/resources/fields.html#default-values. I didn't test it yet but this could be the solution for this issue.
@royduin oh fantastic! That is much better than the withMeta way. @tongtastic can you give it a try and see if it solves your problem? :)
Just tested it myself, it works when creating a new resource but doesn't work when adding a new layout when editing a resource. Which is preferable but logical that it doesn't work from Nova itself. Which means editing a resource will fill empty fields.
Wanna share my current implementation (it's a very particular case, but you will get the idea):
Date::make('Scheduled', 'scheduled_at', function ($value) {
return $value ?? Carbon::now()->addYear();
})->rules('required'),
Will result in:
I'm experiencing this but only on existing models, when creating a new one the default values come through fine.
Hi,
Is there a quick way to set the default value of a field within a flexible layout if no value is currently set? I have tried doing this with ->withMeta(), and passing the standard nova key pairs, however this only works on a fresh page load with previously saved items, not on creation of a new layout item. Any ideas?
Thanks