Laravel 5 - Trait method can has not been applied, because there are collisions with other trai
1、Laravel 5 - Trait method can has not been applied, because there are collisions with other trait methods on App\User?
当使用的多个 trait
中包含了相同的方法名,将会发生冲突,冲突错误信息如下:
FatalErrorException in User.php line 43:
Trait method xxxxxx has not been applied, because there are collisions with other trait methods on App\Http\models\User
和 SoftDeletes 的 restore 冲突
由于 EntrustUserTrait
和 SoftDeletes
两个 trait
都包含 restore
方法,所以当我们对用户 Model 使用软删除的时候同时集成 Entrust
的时候就会导致冲突。
解决方法就是引用两个 trait
时为 restore
方法设置别名,然后重写一个 restore
方法,分别调用两个restore
方法。代码如下:
class User extends Model implements AuthenticatableInterface
{use Authenticatable;use EntrustUserTrait { EntrustUserTrait::restore as private restoreA; }use SoftDeletes { SoftDeletes::restore as private restoreB; }/*** 解决 EntrustUserTrait 和 SoftDeletes 冲突*/public function restore(){$this->restoreA();$this->restoreB();}
}
和 Authorizable 的 can 冲突
解决办法是将 EntrustUserTrait
的 can
方法改一个别名,然后使用 Authorizable
中的 can
,代码如下
use Authenticatable, CanResetPassword, PresentableTrait, Authorizable, EntrustUserTrait {EntrustUserTrait::can as may;Authorizable::can insteadof EntrustUserTrait;
}
{
use Notifiable;
use HasApiTokens;
use RevisionableTrait;
use EntrustUserTrait {
EntrustUserTrait::restore insteadof SoftDeletes;
EntrustUserTrait::boot insteadof RevisionableTrait;
}
use SoftDeletes;
Laravel 5 - Trait method can has not been applied, because there are collisions with other trai相关推荐
- Laravel Trait method broker has not been applied, because there are collisions with other trait meth
在改造Laravel的Auth系统的时候,想把ResetPasswordController和ForgotPasswordController放在自己写的PasswordController里面,然后 ...
- Trait method *** has not been applied, because there are collisions with other trait methods on
文章目录 场景 参考资料 解决 场景 同一个类中引入的多个trait有重复的名字 参考资料 官网文档 解决 两种方式 as 起别称 use WechatBackendExceptionTrait, F ...
- PHP魔术常量trait
作用:PHP中使用trait关键字是为了解决一个类既想集成基类的属性和方法,又想拥有别的基类的方法,而trait一般情况下是和use搭配使用的.trait就是解决了继承只能继承一个的缺陷 实例: & ...
- php traits 使用,php中traits的使用
php是单继承语言,但是如果想在一个class中实现多继承的话,可以使用traits代替. 关于使用.使用关键字trait: 从某个方面,可以理解为class,但是不能实例化 trait中可以定义pu ...
- PHP中的Traits用法详解
PHP是单继承的语言,在PHP 5.4 Traits出现之前,PHP的类无法同时从两个基类继承属性或方法.php的Traits和Go语言的组合功能有点类似, 通过在类中使用use关键字声明要组合的Tr ...
- php 中 Traits 详解
PHP是单继承的语言,在PHP 5.4 Traits出现之前,PHP的类无法同时从两个基类继承属性或方法.php的Traits和Go语言的组合功能有点类似, 通过在类中使用use关键字声明要组合的Tr ...
- 如何覆盖trait函数并从重写函数调用它?
本文翻译自:How to override trait function and call it from the overridden function? Scenario: 场景: trait A ...
- Laravel中使用JWT
资料网址 jwt 官网文档:https://jwt.io/ jwt-auth文档:https://jwt-auth.readthedocs.io/en/develop/laravel-installa ...
- Rust, Trait Object, Object Safty
写了下面一段: async fn put<'a, S, E, F>(store: Arc<Mutex<dyn Storer<'a, dyn Stream<Item ...
最新文章
- pandas数据框,统计某列或者某行数据元素的个数
- 【bzoj2242】[SDOI2011]计算器 EXgcd+BSGS
- HDOJ 1143 Tri Tiling
- 【论文阅读】A social recommender system using item asymmetric correlation
- PerlRegex堆栈溢出的问题
- php写的squid验证辅助器
- linux 压缩和解压缩命令
- 视觉SLAM笔记(47) 优化 PnP 的结果
- 三星Galaxy Z海报曝光 采用双铰链三折叠设计
- You are running Vue in development mode.Make sure to turn on production mode when deploying for p...
- 参加了博客园北京俱乐部4月4日的活动-Nice
- 浅谈长尾理论--《Makers》读后感
- 如何在vs2010中使用ConfigurationManager
- JS 同步本地时间和服务器时间
- Web Server
- 巨头垂涎却不能染指,loT数据库风口已至
- 最常见的电脑数据恢复软件有几种
- 多尺度地理加权回归(MGWR)软件官网下载
- android 安全管家权限管理,安卓应用滥用权限腾讯手机管家可手动关闭
- 一张图轻松搞懂Hive中的join(内连接、左外连接、右外连接、满外连接)