Laravel 未找到未知控制器操作问题
Laravel unknown controller action not found issue
我正在使用 Laravel 7。
面对令人沮丧的错误,
InvalidArgumentException Action App\Http\Controllers\CMSController@viewCmsPages not defined.
成功:
redirect('/admin/view-cms-pages')
失败:
redirect()->action('CMSController@viewCmsPages')
class CmsController extends Controller
{
public function addCmsPage(Request $request)
{
if ($request->isMethod('post')) {
$data = $request->all();
$cmspage->save();
//return redirect('/admin/view-cms-pages')->with('flash_message_success','success');
//why fail...
return redirect()->action('CMSController@viewCmsPages')->with('flash_message_success', 'success');
}
return view('admin.pages.add_cms_page');
}
public function viewCmsPages()
{
return view('admin.pages.view_cms_pages');
}
}
Route::group(['middleware' => ['adminlogin']], function () {
Route::get('/admin/view-cms-pages','CmsController@viewCmsPages');
//i try to add in this resource version also still can't call to
Route::resource('/admin/pages', 'CMSController');
});
当我运行php artisan route:list
时,我可以看到在列表中注册了CMSController@viewCmsPages
在你的控制器上试试这个:
return redirect()->route('cms.view')->with('flash_message_success', 'success');
然后在 web.php 上添加路线名称:
// Add name for the route
Route::get('/admin/pages', 'CMSController@viewCmsPages')->name ('cms.view');
如果你有客户路由,你应该先注册它,资源路由只对方法[index,create,store,show,destory,edit,update]有效
我正在使用 Laravel 7。
面对令人沮丧的错误,
InvalidArgumentException Action App\Http\Controllers\CMSController@viewCmsPages not defined.
成功:
redirect('/admin/view-cms-pages')
失败:
redirect()->action('CMSController@viewCmsPages')
class CmsController extends Controller
{
public function addCmsPage(Request $request)
{
if ($request->isMethod('post')) {
$data = $request->all();
$cmspage->save();
//return redirect('/admin/view-cms-pages')->with('flash_message_success','success');
//why fail...
return redirect()->action('CMSController@viewCmsPages')->with('flash_message_success', 'success');
}
return view('admin.pages.add_cms_page');
}
public function viewCmsPages()
{
return view('admin.pages.view_cms_pages');
}
}
Route::group(['middleware' => ['adminlogin']], function () {
Route::get('/admin/view-cms-pages','CmsController@viewCmsPages');
//i try to add in this resource version also still can't call to
Route::resource('/admin/pages', 'CMSController');
});
当我运行php artisan route:list
时,我可以看到在列表中注册了CMSController@viewCmsPages
在你的控制器上试试这个:
return redirect()->route('cms.view')->with('flash_message_success', 'success');
然后在 web.php 上添加路线名称:
// Add name for the route
Route::get('/admin/pages', 'CMSController@viewCmsPages')->name ('cms.view');
如果你有客户路由,你应该先注册它,资源路由只对方法[index,create,store,show,destory,edit,update]有效