Reputation: 2550
I am building an edit details view and the basic purpose is to update the values entered previously. I read that the best way to do this would be using Form Model Binding. Nevertheless, this seems very risky as the interaction is happening directly on the model (and validation is taking place in controller.
What is your input on this? Is it the best approach to do edit data form?
Upvotes: 2
Views: 423
Reputation: 22395
Model form binding doesn't mean that it will automatically update the existing model with the data once it's posted -- you still need to manually write that logic. It's simply a way for when using laravels Form Builder i.e. Form::text('username')
to attempt to automatically map the 'username' field and use it's value in the text. That's it. No data is automatically updated so simply using model form-binding isn't 'risky'
Instead of doing
Email: {{ Form::text('email', user.email) }}
Username: {{ Form::text('username', user.username) }}
You can simplify this by doing:
{{ Form::model(user) }}
Email: {{ Form::text('email') }}
Username: {{ Form::text('username') }}
Upvotes: 4