Laravel form model binding

后端 未结 2 1885
无人共我
无人共我 2020-12-07 16:49

I\'ve been reading about this feature: http://laravel.com/docs/html#form-model-binding

And it looks really neat, but there are couple of things that I\'m not certain

2条回答
  •  忘掉有多难
    2020-12-07 17:22

    In Laravel 5.1 for relation model binding you just need to eager load relation table(s):

    $user = User::with(['address'])->find($id);
    

    And in view set fields names as array:

    {!! Form::model($user, ['route' => ['user.update', $user->id]]) !!}
        {!! Form::text('address[street]') !!}
        {!! Form::text('address[number]') !!}
    {!! Form::close() !!}
    

提交回复
热议问题