I am facing the same issue trying to redirect guests to HomeController index action. Here is my code with Laravel 5.0.27:
Route::get('/', ['as' => '/', function() {
if (Auth::guest())
return redirect()->action('HomeController@index');
$loggedInHomeUrl = ...;
return redirect($loggedInHomeUrl);
}]);
The error message says:
InvalidArgumentException thrown with message "Action App\Http\Controllers\HomeController@index not defined."
My controller namespace is
namespace App\Http\Controllers;
I can't see what is wrong.
I tried invoking redirect()->action(...)
with many other controllers and actions but I can't manage to make this method work.
Could anyone point me to the error in the code above?
Having the same issue... everything looks fine... but it isn't working...
I just had this problem, it seems you need to add the controller action as a route in your routes.php file and then you're able to map the controller action through the redirect.
aminashoftehyazdi liked this reply
You can declare a route like:
Route::get('home', 'HomeController@index');
And then:
Route::get('/', function() {
if (Auth::guest()) {
return redirect('home');
}
$loggedInHomeUrl = 'someUrl';
return redirect($loggedInHomeUrl);
});
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community