Laravel: Trait method guard 没有被应用,因为在 App\Http\Controllers\Auth\AuthController 上与其他 trait 方法有冲突
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44789114/
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
Laravel: Trait method guard has not been applied, because there are collisions with other trait methods on App\Http\Controllers\Auth\AuthController
提问by Marcus Christiansen
I'm updating to Laravel 5.4 and am receiving this error message:
我正在更新到 Laravel 5.4 并收到此错误消息:
Trait method guard has not been applied, because there are collisions with other trait methods on App\Http\Controllers\Auth\AuthController
没有应用Trait方法guard,因为在App\Http\Controllers\Auth\AuthController上与其他trait方法有冲突
Here's my 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\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']),
]);
}
}
I've updated:
我已经更新:
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
But I'm 100% sure what the error message means.
但我 100% 确定错误消息的含义。
回答by apokryfos
Laravel internally used trait AuthenticatesAndRegistersUsers
Laravel 内部使用的 trait AuthenticatesAndRegistersUsers
Because both traits shared some methods Laravel used the following:
因为这两个 trait 共享了一些 Laravel 使用的方法:
use AuthenticatesUsers, RegistersUsers {
AuthenticatesUsers::redirectPath insteadof RegistersUsers;
AuthenticatesUsers::guard insteadof RegistersUsers;
}
If you do the same you need to make the same decision (not much of a decision here, both methods serve the same purpose).
如果你做同样的事情,你需要做出同样的决定(这里不是什么决定,两种方法都有相同的目的)。
Since then Laravel has of course split the single AuthController into 2 thus removing the need to do this.
从那时起,Laravel 当然将单个 AuthController 拆分为 2 个,从而消除了这样做的需要。