1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace App\Models\Admin;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsToMany;
- class AdminRole extends Model
- {
- protected $table = 'admin_roles';
-
- static $consultantSlug = 'consultant';
-
- protected $fillable = ['name', 'slug','subsite_id'];
- public function permissions()
- {
- return $this->belongsToMany(AdminPermission::class, 'admin_role_permissions', 'role_id', 'permission_id');
- }
- /**
- * A role belongs to many users.
- *
- * @return BelongsToMany
- */
- public function administrators() : BelongsToMany
- {
- $pivotTable = config('admin.database.role_users_table');
- $relatedModel = config('admin.database.users_model');
- return $this->belongsToMany($relatedModel, $pivotTable, 'role_id', 'user_id');
- }
- /**
- * Detach models from the relationship.
- *
- * @return void
- */
- protected static function boot()
- {
- parent::boot();
- static::deleting(function ($model) {
- $model->administrators()->detach();
- $model->permissions()->detach();
- });
- }
- public static function roleArr()
- {
- return self::when(get_subsite_id() > 0, function ($query) {
- $query->whereIn('subsite_id', [-1,get_subsite_id()]);
- })->pluck('name', 'id');
- }
- }
|