13

After upgrading the laravel 5.8 to laravel 6.x I am getting this error:

Undefined class constant 'App\Providers\RouteServiceProvider::HOME'

Before upgrading the application login system was the custom. After upgrading to laravel 6.x I want to use laravel default authentication. I created authentication through php artisan ui:auth and I copied controllers from fresh laravel app/Http/Controllers/Auth folder with auth related controllers like - LoginController, RegisterController etc.

What should I do to solve the above error? Would someone help me, please?

Rashed Hasan
  • 3,414
  • 5
  • 29
  • 71

4 Answers4

20

In Laravel 6 the $redirectTo property in the auth controllers was updated so that it was easier to change across the board. Link to PR.

To fix the error you can either add the following to your App\Providers\RouteServiceProvider.php class:

/**
 * The path to the "home" route for your application.
 *
 * @var string
 */
public const HOME = '/home';

or in each of your auth controller update the $redirectTo property to be the route that you want to use:

protected $redirectTo = RouteServiceProvider::HOME;

becomes

protected $redirectTo = '/the-path-you-want-to-redirect-to';
Rwd
  • 27,979
  • 5
  • 47
  • 62
1

I came across the same issue, I found that it's not the same constant in the RouteServiceProvider class, you will find Home not HOME. I think this issue came with LARAVEL because my project is new.

my LARAVEL version is 7.7.0

mouad36
  • 78
  • 5
0

in my case:

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';
    public const HOME = '/home';

just add this line

public const HOME = '/home';

as Laravel documents said https://laravel.com/docs/7.x/authentication#included-authenticating

saber tabatabaee yazdi
  • 2,078
  • 3
  • 26
  • 40
-1

in my case i've changed the word HOMEin protected $redirectTo = RouteServiceProvider::HOME;into lowercase home like that protected $redirectTo = RouteServiceProvider::home; that what caused me the error above, so i've just put it again in uppercase and now it's Ok !

Haleem
  • 1