[英]MethodNotAllowedHttpException while submitting form in Laravel 5.2
[英]MethodNotAllowedHttpException in submitting a form in Laravel
我正在尝试提交表单以更新tbl_pages列。 所以要更新我使用复选框的特定列。 这是我的看法。
这是我的看法 :
{!!Form::open([
'method' => 'patch',
'route' => 'pages.update'
])!!}
<p>{!! Form::checkbox('pages[]', $page->id, false, array('class' => 'checkboxes')) !!}</p>
{!!Form::submit('Move to Trash', array('class' => 'btn btn-default', 'name'=> 'movetrash'))!!}
{!!Form::close()!!}
我在PageController.php中的 update()方法看起来像这样。
public function update(Request $request, $id)
{
if(Input::get('movetrash')) {
$pagesarray = Input::get('pages'); //getting checkbox values from view
if(!empty($pagesarray)){
foreach($pagesarray as $pageid){
$page = Pages::where('id', $pageid) -> first();
$page -> active = 0;
$page -> save();
}
\Session::flash('movedtotrash', 'Pages has been successfully MOVED TO TRASH');
}
return redirect()->route('pages');
}
}
我的routes.php如下所示:
Route::group(['middleware' => ['web'], 'prefix' => 'pages'], function () {
//
Route::get('trash', 'PagesController@trashpage');
Route::get('movetotrash/{id}', 'PagesController@movetotrash');
Route::get('restore/{id}', 'PagesController@restore');
Route::get('trashmultiple', [
'as' => 'pages.trashmultiple', 'uses' => 'PagesController@update'
]);
Route::resource('', 'PagesController'); // here is the problem
});
在routes.php中,我感觉无法定义 Route::resource('pages', 'PagesController');
这样,即使我这样做,我NotFoundHttpException in RouteCollection.php
收到此错误NotFoundHttpException in RouteCollection.php
我猜这是我无法在'route' => 'pages.update'
任何对此的解决方案将非常有帮助。
谢谢! (提前)
更新路线需要一个ID。 运行php artisan route:list
以查看与更新关联的路由的url(如果存在)。 还使用Route::resource('/', 'PagesController');
{!!Form::open([
'method' => 'patch',
'route' => [pages.update, $id]
])!!}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.