【发布时间】:2019-08-07 20:31:58
【问题描述】:
我有一个项目模型和用户模型。 在用户模型中有一个检查用户是否有权限的功能:
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
public function hasPermission($permission){
$code = Permission::where('name',$permission)->first()->id-1;
$total = $this->group->permissions;
return ($total & pow(2,$code));
}
}
我正在尝试通过此功能过滤项目,例如:
Items::where('sell_price','>',0)->where('user.hasPermission','SellItems');
items 模型如下所示:
class Items extends Model
{
public function user(){
return $this->belongsTo('App\User');
}
}
【问题讨论】: