Support the ongoing development of Laravel.io →
posted 9 years ago
Requests
Last updated 1 year ago.
0

Is your ArticlesController in App\Http\Controllers namespace?

0

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?

Last updated 8 years ago.
0

Having the same issue... everything looks fine... but it isn't working...

0

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

1

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);
});
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ilikourou ilikourou Joined 22 Apr 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.