blue-twilight/app/Group.php

34 lines
693 B
PHP
Raw Permalink Normal View History

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Group extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name'
];
public function adminPermissions()
{
return $this->belongsToMany(Permission::class, 'admin_group_permissions');
}
public function hasAdminPermission(Group $group, Permission $permission)
{
return $this->adminPermissions()->where([
'permission_id' => $permission->id
])->count() > 0;
}
public function users()
{
return $this->belongsToMany(User::class, 'user_groups');
}
}