feat: implement admin management
This commit is contained in:
+11
-2
@@ -79,9 +79,18 @@ class Admin extends User
|
||||
{
|
||||
return $this->hasMany(AdminPermission::class);
|
||||
}
|
||||
public function hasPermission(string $permission): bool
|
||||
public function avatar()
|
||||
{
|
||||
if ($this->role === AdminRole::SUPERADMIN) {
|
||||
return $this->hasOne(AdminAvatar::class);
|
||||
}
|
||||
public function isSuperAdmin(): bool
|
||||
{
|
||||
return $this->role === \App\Enums\Admin\AdminRole::SUPERADMIN;
|
||||
}
|
||||
|
||||
public function canAccess(string $permission): bool
|
||||
{
|
||||
if ($this->isSuperAdmin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class AdminAvatar
|
||||
*
|
||||
* @property int $id
|
||||
* @property int|null $file_id
|
||||
* @property int $admin_id
|
||||
* @property Carbon $created_at
|
||||
*
|
||||
* @property Admin $admin
|
||||
* @property File|null $file
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class AdminAvatar extends Model
|
||||
{
|
||||
protected $table = 'admin_avatars';
|
||||
|
||||
public static $snakeAttributes = false;
|
||||
|
||||
protected $casts = [
|
||||
'file_id' => 'int',
|
||||
'admin_id' => 'int'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'file_id',
|
||||
'admin_id'
|
||||
];
|
||||
|
||||
public function admin()
|
||||
{
|
||||
return $this->belongsTo(Admin::class);
|
||||
}
|
||||
|
||||
public function file()
|
||||
{
|
||||
return $this->belongsTo(File::class);
|
||||
}
|
||||
}
|
||||
+6
-2
@@ -12,7 +12,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class File
|
||||
*
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $extension
|
||||
@@ -21,7 +21,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
* @property string $path
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
*
|
||||
*
|
||||
* @property Collection|Flight[] $flights
|
||||
* @property Collection|User[] $users
|
||||
*
|
||||
@@ -53,4 +53,8 @@ class File extends Model
|
||||
{
|
||||
return $this->hasMany(User::class);
|
||||
}
|
||||
public function adminAvatar()
|
||||
{
|
||||
return $this->hasOne(AdminAvatar::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user