Laravel 5 - Trait method can has not been applied, because there are collisions with other trai
2017-05-25 16:12
1661 查看
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; }
2、RevisionableTrait conflicts with EntrustUserTrait?
然而EntrustUserTrait 中与RevisionableTrait 中的boot 重复造成 RevisionableTrait conflicts with
EntrustUserTrait 的原因,解决办法
在user.php model 中可以使用
class User extends Authenticatable
{
use Notifiable;
use HasApiTokens;
use RevisionableTrait;
use EntrustUserTrait {
EntrustUserTrait::restore insteadof SoftDeletes;
EntrustUserTrait::boot insteadof RevisionableTrait;
}
use SoftDeletes;
}
3、Trait method boot has not been applied,
because there are collisions with other trait methods on App\Models\User?
如果抛出了上面的 错误,就是boot重复了,可以看看第二个问题
4、The thing that bothers me is
that I don't have deleted_at column in my user table?
如果出现deleted_at 错误,就是数据库少了deleted_at字段,你可以新增一个migration,添加这个字段
相关文章推荐
- Laravel Trait method broker has not been applied, because there are collisions with other trait meth
- has been registered with some other pool, and can not register it again.
- EntityFramework4.0中遇到New transaction is not allowed because there are other threads running in the session
- Somebody~why I can not be there where you are??????????????
- 自定义标题时you can not combine custom title with other title features
- "Loads are not reorderd with other loads" is a FACT!!
- tomcat 7 WARNING: A context path must either be an empty string or start with a '/' and do not end with a '/'. The path [/] does not meet these criteria and has been changed to []
- The key you are authenticating with has been marked as read only的解决方法
- Model compatibility cannot be checked because the database does not contain model metadata. Ensure that IncludeMetadataConvention has been added to the DbModelBuilder conventions
- This application has not been initialized with an ESRI license and will not function correctly 解决办法
- mod_ssl has been requested but can not be built due to prerequisite failures
- has a relation with model <class '***'>, which has either not been installed or is abstract.
- error: mod_deflate has been requested but can not be built due to prerequisite failures
- "Loads are not reorderd with other loads" is a FACT!! 续:不要指望 volatile
- System.NotSupportedException: This method explicitly uses CAS policy, which has been obsoleted by th
- There are multiple modules with names that only differ in casing. This can lead to unexpected....
- sharepoint2010 The Ribbon Tab with id: "Ribbon.Read" has not been made
- Hololens错误提示:can't be loaded because it was not built with the right version or build target.
- SQL恢复备份遇到错误 - his differential backup cannot be restored because the database has not been restored
- Can not delete a master page "This item cannot be deleted because it is still referenced by other pa