After updating from Laravel 4.2 to 5.0, I am getting the following message in almost every page of my application:
InvalidArgumentException in UrlGenerator.php line 561: Action ArticlesController@create not defined.
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']);
And in my controller:
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
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:
Since we are not going to migrate to full namespacing in this guide, add the app/Http/Controllers directory to the classmap directive of your composer.json file. Next, you can remove the namespace from the abstract app/Http/Controllers/Controller.php base class. Verify that your migrated controllers are extending this base class.
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.
I was getting the same error message, and it was because I'd completely forgotten that I needed to add this to routes/web.php
:
Route::get('myUrlPath', 'HomeController@myActionName');
I had been trying to do this from another controller action:
return redirect()->action('HomeController@myActionName')->with('windowTitle', 'Error. Please contact us.')->with('message', $message);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With