0
我有4個表:laravel關係的表
用戶(ID,ROLE_ID)
角色(ID)
permission_role(ROLE_ID,permission_id)
許可(ID,姓名)
用戶模型
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Zizaco\Entrust\Traits\EntrustUserTrait;
class User extends Authenticatable
{
use Notifiable;
use EntrustUserTrait;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function roles()
{
return $this->hasOne('App\Role', 'id', 'role_id');
}
}
榜樣
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Zizaco\Entrust\EntrustRole;
class Role extends EntrustRole
{
public function users()
{
return $this->belongsTo('App\User','role_id','id');
}
public function permissions()
{
return $this->belongsToMany('App\Permission','permission_role');
}
}
權限模型:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Zizaco\Entrust\EntrustPermission;
class Permission extends EntrustPermission
{
public function roles()
{
return $this->belongsToMany('App\Role','permission_role');
}
}
,我想在我的控制器進行測試,看是否通過用戶如果條件有權限delete_article,任何幫助嗎?並感謝