Laravel:未找到特性“Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44788861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:13:19  来源:igfitidea点击:

Laravel: Trait 'Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers' not found

phplaravelcomposer-php

提问by Marcus Christiansen

I'm updating to Laravel 5.4 and am receiving the following error message when trying to display the login screen.

我正在更新到 Laravel 5.4 并在尝试显示登录屏幕时收到以下错误消息。

I'm receiving the following error message:

我收到以下错误消息:

Trait 'Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers' not found

特征 'Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers' 未找到

Here's is the AuthController class:

这是 AuthController 类:

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

use AuthenticatesAndRegistersUsers, ThrottlesLogins;

/**
 * Where to redirect users after login / registration.
 *
 * @var string
 */
protected $redirectTo = '/home';

/**
 * Where to redirect users after logout.
 *
 * @var string
 */
protected $redirectAfterLogout = '/login';

/**
 * Create a new authentication controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware($this->guestMiddleware(), ['except' => ['getLogout']]);
}

/**
 * Get a validator for an incoming registration request.
 *
 * @param  array  $data
 * @return \Illuminate\Contracts\Validation\Validator
 */
protected function validator(array $data)
{
    return Validator::make($data, [
        'name' => 'required|max:255',
        'email' => 'required|email|max:255|unique:users',
        'password' => 'required|min:6|confirmed',
    ]);
}

/**
 * Create a new user instance after a valid registration.
 *
 * @param  array  $data
 * @return User
 */
protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
    ]);
}
}

采纳答案by omadonex

with laravel 5.4 we have some changes in this trait. Now we have two different traits:

在 Laravel 5.4 中,我们对这个特性进行了一些更改。现在我们有两个不同的特征:

use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

And if you install a fresh 5.4 laravel application you will see that now you have LoginController and RegisterController instead of AuthController

如果你安装一个新的 5.4 laravel 应用程序,你会看到现在你有 LoginController 和 RegisterController 而不是 AuthController

回答by Hyman Kinsella

If you're in Laravel 7+, you'll need to first install the laravel/uipackage (since this contains auth backend code) and then

如果您使用的是 Laravel 7+,则需要先安装该laravel/ui软件包(因为它包含身份验证后端代码),然后

<?php

use Illuminate\Foundation\Auth\RegistersUsers;

class RegisterController extends Controller
{
    use RegistersUsers;
}

回答by Wissa

I think you need to use this trait instead

我认为你需要改用这个特性

use Illuminate\Foundation\Auth\AuthenticatesUsers;