问题描述
从Laravel 4.2更新到5.0后,我几乎在应用程序的每个页面中都收到以下消息:
After updating from Laravel 4.2 to 5.0, I am getting the following message in almost every page of my application:
UrlGenerator.php第561行中的InvalidArgumentException:未定义操作ArticlesController @ create.
在我的route.php文件中,我拥有:
In my routes.php file I have:
Route::get('articles/create', ['as' => 'articles.create', 'uses' => 'ArticlesController@create']);
Route::post('articles/create', ['as' => 'articles.create.handle', 'uses' => 'ArticlesController@handleCreate']);
在我的控制器中:
class ArticlesController extends Controller {
public function create()
{
$input=null;
if (Input::old()) {
$input = Input::old();
}
$tagsJson = Tag::all()->toJson();
$categories = ArticleCategory::all();
return View::make('admin.articles.create', compact(array('tagsJson', 'categories', 'input')));
}
public function handleCreate()
{
$input = Input::all();
if ($input['op']=="preview") {
return redirect()->action('ArticlesController@create')->withInput();
} else if ($input['op']=="post") {
//
}
}
}
我得到的错误来自此行:
The error I get comes from this line:
return redirect()->action('ArticlesController@create')->withInput();
有帮助吗?谢谢,伊利亚斯
Any help?Thanks, Ilias
推荐答案
您会收到此错误,因为Laravel 5默认使用命名空间.官方Laravel 5升级指南说明了有关迁移控制器的以下内容:
You are getting this error because Laravel 5 uses namespacing by default. The official Laravel 5 upgrade guide says the following about migrating your controllers:
在您的app/Providers/RouteServiceProvider.php文件中,将namespace属性设置为null.
In your app/Providers/RouteServiceProvider.php file, set the namespace property to null.
在控制器"下的此处列出.
Listed here under "controllers".
最后一行可能会解决您的问题.
The last line is probably the one that will solve your issue.
这篇关于Laravel动作未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!