Laravel:未找到特征“IlluminateFoundationAuthAuthenticatesAndRegistersUsers"

2022-01-21 00:00:00 php laravel composer-php

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

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

我收到以下错误消息:

找不到特征IlluminateFoundationAuthAuthenticatesAndRegistersUsers"

Trait 'IlluminateFoundationAuthAuthenticatesAndRegistersUsers' not found

这里是 AuthController 类:

Here's is the AuthController class:

<?php

namespace AppHttpControllersAuth;

use AppUser;
use Validator;
use AppHttpControllersController;
use IlluminateFoundationAuthThrottlesLogins;
use IlluminateFoundationAuthAuthenticatesAndRegistersUsers;

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 IlluminateContractsValidationValidator
 */
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']),
    ]);
}
}

推荐答案

在 laravel 5.4 中,我们在这个特性上有了一些变化.现在我们有两个不同的特征:

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

use IlluminateFoundationAuthRegistersUsers;
use IlluminateFoundationAuthAuthenticatesUsers;

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

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

相关文章