Laravel 集体自定义表单,动作 Controller@update 未定义
Laravel collective custom forms, action Controller@update not defined
这是我的路线:
Route::get('admin/edit-news/{id}', 'AdminNewsController@edit');
我的控制器@更新方法:
public function update(Request $request, $id)
{
$news = News::find($id);
$news->title = $request->input('title');
$news->content = $request->input('content');
$news->save();
return redirect ('/admin');
}
我的自定义表单视图:
{{ Form::open(['action' => ['AdminNewsController@update', $news->id], 'method' => 'POST']) }}
{{ Form::bsText('title', $news->title) }}
{{ Form::bsTextArea('content', $news->content) }}
{{ Form::hidden('_method', 'PUT') }}
{{ Form::bsSubmit('Confirm', ['class' => 'btn btn-primary center-block']) }}
{!! Form::close() !!}
我收到的错误是
"Action App\Http\Controllers\AdminNewsController@update not defined. (View: D:\xampp\htdocs\laravelhotel\resources\views\admin\news\edit_news.blade.php)"
我不知道为什么,因为我放置的动作是更新功能,并且我已经在 FormServiceProvider 中注册了所有组件。
如果使用PUT方法,由POSTform-method和_method
字段模拟({{ Form::hidden('_method', 'PUT') }}
),需要使用相应的路由:
Route::put('admin/edit-news/submit', 'AdminNewsController@update');
// ^^^
这是我的路线:
Route::get('admin/edit-news/{id}', 'AdminNewsController@edit');
我的控制器@更新方法:
public function update(Request $request, $id)
{
$news = News::find($id);
$news->title = $request->input('title');
$news->content = $request->input('content');
$news->save();
return redirect ('/admin');
}
我的自定义表单视图:
{{ Form::open(['action' => ['AdminNewsController@update', $news->id], 'method' => 'POST']) }}
{{ Form::bsText('title', $news->title) }}
{{ Form::bsTextArea('content', $news->content) }}
{{ Form::hidden('_method', 'PUT') }}
{{ Form::bsSubmit('Confirm', ['class' => 'btn btn-primary center-block']) }}
{!! Form::close() !!}
我收到的错误是
"Action App\Http\Controllers\AdminNewsController@update not defined. (View: D:\xampp\htdocs\laravelhotel\resources\views\admin\news\edit_news.blade.php)"
我不知道为什么,因为我放置的动作是更新功能,并且我已经在 FormServiceProvider 中注册了所有组件。
如果使用PUT方法,由POSTform-method和_method
字段模拟({{ Form::hidden('_method', 'PUT') }}
),需要使用相应的路由:
Route::put('admin/edit-news/submit', 'AdminNewsController@update');
// ^^^