Laravel:Trait方法保护尚未应用,因为App \ Http \ Controllers \ Auth \ AuthController上存在与其他特征方法的冲突

时间:2017-06-27 20:15:36

标签: php laravel composer-php laravel-5.4

我正在更新到Laravel 5.4并收到此错误消息:

  

尚未应用Trait方法保护,因为在App \ Http \ Controllers \ Auth \ AuthController上存在与其他特征方法的冲突

这是我的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\RegistersUsers;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

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 RegistersUsers, AuthenticatesUsers;

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

我已更新:

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

但我100%肯定错误信息的含义。

1 个答案:

答案 0 :(得分:4)

Laravel内部使用特质AuthenticatesAndRegistersUsers

因为这两个特征共享了一些方法,所以Laravel使用了以下内容:

use AuthenticatesUsers, RegistersUsers {
    AuthenticatesUsers::redirectPath insteadof RegistersUsers;
    AuthenticatesUsers::guard insteadof RegistersUsers;
}

如果你这样做,你需要做出同样的决定(这里没有太大的决定,两种方法都有相同的目的)。

从那时起,Laravel当然将单个AuthController拆分为2,因此无需执行此操作。