使用Zizaco委托包并尝试让所有用户与他们的角色一起
我有用户模型
use Laravel\Passport\HasApiTokens;
use Illuminate\Database\Eloquent\Model;
use Zizaco\Entrust\Traits\EntrustUserTrait;
class User extends Model implements AuthenticatableContract
{
use Authenticatable,HasApiTokens, EntrustUserTrait;
protected $fillable = [
'name', 'email', 'password','status'
];
protected $hidden = [
'password', 'remember_token',
];
public function role()
{
return $this->belongsTo('App\Role', 'id');
}
}
现在是App \ Role
use Zizaco\Entrust\EntrustRole;
class Role extends EntrustRole
{
}
当我使用
获取用户时 $sortval = explode("|",$request->sort);
return \App\User::orderBy( $sortval[0], $sortval[1])
->with("role") //added the relationship
->paginate($request->per_page);
即使为用户分配了角色,上述角色也始终返回null。