You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.4 KiB
63 lines
1.4 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
class AdminRoles extends Model
|
|
{
|
|
use HasFactory, Notifiable, SoftDeletes;
|
|
|
|
protected $primaryKey = 'id';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable
|
|
= [
|
|
'name'
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for serialization.
|
|
* @var array<int, string>
|
|
*/
|
|
protected $hidden
|
|
= [
|
|
'updated_at',
|
|
'deleted_at',
|
|
];
|
|
|
|
public static function getRolesList(): array
|
|
{
|
|
$where = ['status' => 1];
|
|
$columns = ['id', 'name'];
|
|
return self::query()->where($where)->select($columns)->get()
|
|
->toArray();
|
|
}
|
|
|
|
public function adminUsers(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
AdminUsers::class,
|
|
AdminRoleUsers::class,
|
|
'role_id',
|
|
'user_id'
|
|
);
|
|
}
|
|
|
|
public function menus(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
AdminMenu::class,
|
|
AdminRoleMenu::class,
|
|
'role_id',
|
|
'menu_id'
|
|
);
|
|
}
|
|
}
|
|
|