因为有朋友在问我 [ here], 而我之前也正好遇到过,所以记录下。
当使用的多个 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
由于 EntrustUserTrait和 SoftDeletes两个 trait都包含 restore方法,所以当我们对用户 Model 使用软删除的时候同时集成 Entrust的时候就会导致冲突。
在线证件照系统是一套完善的冲印行业解决方案,致力于解决用户线上拍摄证件照,拍摄最美最标准证件照的使命。证件照免费版功能:后台统计:当天制作、当天新增、支持规格、近7日统计规格列表:筛选查看、编辑用户列表:筛选查看常见问题:筛选查看、新增、编辑、删除小程序设置:应用设置、流量主设置小程序跳转:筛选查看、新增、编辑、删除关注公众号:引导设置系统要求:系统:Linux系统(centos x64)运行环境
1
解决方法就是引用两个 trait时为 restore方法设置别名,然后重写一个 restore方法,分别调用两个 restore方法。代码如下:
class User extends Model implements AuthenticatableInterface { use Authenticatable; use EntrustUserTrait { restore as private restoreA; } use SoftDeletes { restore as private restoreB; } /** * 解决 EntrustUserTrait 和 SoftDeletes 冲突 */ public function restore() { $this->restoreA(); $this->restoreB(); }}解决办法是将 EntrustUserTrait的 can方法改一个别名,然后使用 Authorizable中的 can,代码如下
use Authenticatable, CanResetPassword, PresentableTrait, Authorizable, EntrustUserTrait { EntrustUserTrait::can as may; Authorizable::can insteadof EntrustUserTrait;}参考: Laravel 5.1.11 - Trait method can has not been applied, because there are collisions with other trait methods on App\User
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号