0
点赞
收藏
分享

微信扫一扫

Laravel Trait method broker has not been applied, because there are collisions with other trait meth

在改造Laravel的Auth系统的时候,想把ResetPasswordController和ForgotPasswordController放在自己写的​​PasswordController​​里面,然后出现下面错误:

Trait method broker has not been applied, because there are collisions with other trait methods on App\Http\Controllers\PasswordController

出现这个错误的原因是引用的两个trait里面有同名的broker函数,出现了冲突。

public function broker()
{
return Password::broker();
}

这里的解决办法有两种,
一是用其中一个trait里的broker方法覆盖另外一个trait的同名方法,因为两个方法内容是一致的,所以我这里直接选择insteadof覆盖;

class PasswordController extends Controller {
//解决冲突,两个trait里面都有broker方法,但是内容是一致的
use ResetsPasswords, SendsPasswordResetEmails {
ResetsPasswords::broker insteadof SendsPasswordResetEmails;
}

二是给他们用as起别名,这样就不会有冲突了。as关键词还有另外一个用途,那就是修改方法的访问控制。
参考链接: ​​
原始链接:​​​http://tabalt.net/blog/php-traits/​​


举报

相关推荐

0 条评论