Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Form Model Binding with Relationships

Is it possible to bind a form with a model that has relationships? For example I have a Order model that has a one to many with a Details model. That would save a lot of time with

@foreach($order->details as $detail)
{{ Form::text('product_name', Input::old('product_name') ? Input::old('product_name') : detail->product_name)
@endforeach
like image 290
Casey Avatar asked Dec 14 '22 23:12

Casey


1 Answers

For a one-to-one relation it's possible to use something like this:

Form::text('detail[product_name]')

In this case $order->detail->product_name will be populated in the given text box if an instance of Order model is bound to the from using Form::model($order) with the related model Detail but it may not possible for one-to-many because simply there will be a collection and you need a loop.

like image 196
The Alpha Avatar answered Mar 06 '23 07:03

The Alpha