我遇到一个错误:Laravel - 路由更新错误
Some mandatory parameters are missing ("users") to generate a URL for route "users.update".
我有这一套对我的看法:
{{ Form::open(array('action' => array('[email protected]'))) }}
<div> {{ Form::label('username', 'Username:') }}
{{ Form::text('username', $user->username , array('class' => 'form-control')) }}</div>
<div> {{ Form::label('email', 'Email Address:') }}
{{ Form::text('email', $user->email , array('class' => 'form-control')) }}</div>
<div> {{ Form::label('new_password', 'New Password:') }}
{{ Form::text('new_password', '', array('class' => 'form-control')) }} </div>
<div> {{ Form::label('old_password', 'Old Password:') }}
{{ Form::text('password', '', array('class' => 'form-control')) }} </div>
{{ Form::submit() }}
{{ Form::close() }}
我也有一个功能,在我的控制器连接到更新:
public function update() {
return 'This is an update';
}
最后,当我检查Artisan命令中可用的所有路线时,我发现该更新的路线为:users/{users}
我的代码有什么问题?我试图更新一个用户,它会引发这个错误。
您在表单的action属性中缺少'{user}'参数。 __in simple terms__,你缺少'{{Form :: open(array('action'=> array('UsersController @ update')))}''中的第二个参数。它应该像'{{Form :: open(array('action'=> array('UsersController @ update',$ id)))}}'其中id是用户的id。 – itachi
是的。我刚刚发现,但仍然不能解决问题,因为它是为了更新。无需为更新,存储和删除等操作设置这些变量。 – Bajongskie
然后在routes.php – itachi