Replies: 2 comments 1 reply
-
@RUDIWER Currently the form helper only submits data of properties that were initialized when calling Behind the scenes the form helper needs this default properties to "know" which are relevant to the form and which are just internal properties. When you create a new instance of your customer model via $customer = new Customer();
$customer->toArray(); This will return an empty customer array. This explains why the form data is empty. There are no default properties. Of course you can set the attributes if that works for you. this.$inertia.form({
name: this.customer.name,
...
}), or when instanating the model in Laravel: $customer = new Customer([
'name' => null,
]); Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Are there caveats on using protected $attributes = [ ...... ] annd add all the fields there ? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel - Vue - Inertiajs new form helper
In my controller in make a new model instance for example : $customer = new Customer,
When i come in my vue component i inject thsi new model instance to the form object : form: this.$inertia.form({...this.customer }),
This form right now has no fields in it.
I fill my form and add several fields to the form object.
When i post the form with : this.form.post(this.route('customers.store', this.customer.id)
The request does NOT have the added fields ????
My soluton for the moment is to add all the fields in de Customer model with : protected $attributes = [ ...... ]
But this seems not a elegant solution for me, anyone a idea how to solve this a better way ?
Beta Was this translation helpful? Give feedback.
All reactions