@keithmichelson I’m not sure I understand the question. What are the two models in question?
Form Model Binding with Multiple Models
I made a form that uses 2 models to submit to 2 tables. Now I'm making an edit/update form. Is there a way use 2 models so I can populate the second model field values?
{!! Form::model($article, ['method' => 'PATCH', 'action' => ['ArticlesController@update', $article->id]]) !!}
I have no idea about the syntax but 2 models like this.
{!! Form::model($article, $module, ['method' => 'PATCH', 'action' => ['ArticlesController@update', $article->id]]) !!}
Thanks for any help.
Keith
In one of my projects I have a form submitting to 4 models. Binding and populating the fields I do like:
<div class="form-group">
{!! Form::label('date', 'Climb date', ['class' => 'control-label']) !!}
{!! Form::text('date', null, array( 'class'=>'form-control', 'placeholder'=>'yyyy-mm-dd')) !!}
</div>
<div class="form-group">
{!! Form::label('Route name') !!}
{!! Form::text('name', ( isset($climb->route->name) ? $climb->route->name : null ), array('class'=>'form-control' )) !!}
</div>
<div class="form-group">
{!! Form::label('Area') !!}
{!! Form::text('area', isset($climb->route->area->name) ? $climb->route->area->name : null, array( 'class'=>'form-control' )) !!}
</div>
So as you can see, Climb is the first model. A climb is related to a Route, the second model (a climb of a route, so a climb belongs to a route, a route hasMany climbs). A Route belongs to an Area. And lastly (not shown above), an area belongs to a country.
The code above only works if you have set up the relations in the models.
Please or to participate in this conversation.