简体   繁体   中英

Using Entrust with Laravel built-in Auth system

I used php artisan make:auth command in my Laravel project and this is how my unchanged App\\Models\\User.php looks like:

<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable{

/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'name', 'email', 'password',
];

/**
 * The attributes excluded from the model's JSON form.
 *
 * @var array
 */
protected $hidden = [
    'password', 'remember_token',
];}

Now, according to Entrusts documentation I should change the User.php file to the following:

<?php

use Zizaco\Entrust\Traits\EntrustUserTrait;

class User extends Eloquent
{
    use EntrustUserTrait; // add this trait to your user model

    ...
}

I want to use Laravel built-in Auth system with Entrust user roles. How can I mix these two to work together? As I have read, it is not possible to use multiple extends. Any simple solutions?

With you unchanged class App\\Models\\User put use EntrustUserTrait; inside the class and you will be good to go

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM