laravel形式模型绑定不工作laravel 5.4

时间:2017-02-09 13:15:45

标签: laravel-5 model-binding laravelcollective

我在SO上经历了类似的帖子,但没有任何对我有用,也没有找到相关答案。即使它没有更新数据。

{!! Form::model($editClient, [ 'method' => 'PATCH','route' => ['clients.update', $editClient->id],'class' => 'form-horizontal', 'id'=>'edit-client' ]) !!}

@include('clients._form')

我使用的格式为partial

路线:

Route::resource('clients', 'ClientController');

控制器方法:

public function edit($id)
{
    $editClient = User::findOrFail($id);
    return view('clients.edit', compact('editClient'));
}

HTML:

<div class="form-group">
    <label class="control-label col-sm-2" for="username">Username:</label>
        <div class="col-sm-10">
        <input type="text" class="form-control" id="email" name="user_name" placeholder="Enter Username">
        </div>
   </div>
<div class="form-group">
    <label class="control-label col-sm-2" for="email">Email:</label>
        <div class="col-sm-10">
        <input type="email" class="form-control" id="email" name="email" placeholder="Enter email">
</div>
  </div>
 <div class="form-group">
    <label class="control-label col-sm-2" for="pwd">Password:</label>
    <div class="col-sm-10"> 
    <input type="password" class="form-control" id="pwd" name="password" placeholder="Enter password">
    </div>
  </div>

<div class="form-group">
  <label class="control-label col-sm-2" for="contact">Contact Number:     </label>
<div class="col-sm-10"> 
<input type="number" class="form-control" id="contact" name="contact" placeholder="Enter Contact Number">
</div>
   </div>
<div class="form-group"> 
    <div class="col-sm-offset-2 col-sm-10">
    <button type="submit" class="btn btn-default">Submit</button>
   </div>
</div>
</form>

1 个答案:

答案 0 :(得分:0)

来自Laravel Collective文档的表单模型绑定(https://laravelcollective.com/docs/5.4/html#form-model-binding):

{{ Form::model($user, ['route' => ['user.update', $user->id]]) }}

你有$ editClient,而我认为你的模型可能是$ client