17

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?

4

4 回答 4

26

在 Laravel 6$redirectTo中,auth 控制器中的属性已更新,因此更容易全面更改。链接到 PR

要修复错误,您可以将以下内容添加到您的App\Providers\RouteServiceProvider.php课程中:

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

或在您的每个身份验证控制器中将$redirectTo属性更新为您要使用的路由:

protected $redirectTo = RouteServiceProvider::HOME;

变成

protected $redirectTo = '/the-path-you-want-to-redirect-to';
于 2020-01-18T12:19:49.160 回答
2

在我的情况下:

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';

只需添加这一行

public const HOME = '/home';

正如 Laravel 文档所说https://laravel.com/docs/7.x/authentication#included-authenticating

于 2020-06-23T07:41:31.657 回答
1

我遇到了同样的问题,我发现RouteServiceProvider类中的常量不一样,你会发现Home不是HOME。我认为这个问题来自 LARAVEL,因为我的项目是新的。

我的 LARAVEL 版本是 7.7.0

于 2020-05-08T11:41:09.563 回答
-1

在我的情况下,我已经把这个词改成HOMEprotected $redirectTo = RouteServiceProvider::HOME;小写homeprotected $redirectTo = RouteServiceProvider::home;这就是导致我上面错误的原因,所以我只是把它再次变成大写,现在没关系了!

于 2020-04-29T06:58:38.760 回答