revert manualy model, migration. and seeder menu and route
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Menu extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $fillable = [
|
||||
'parent_id',
|
||||
'name',
|
||||
'route_or_url',
|
||||
'icon',
|
||||
'enable',
|
||||
'position',
|
||||
'actives',
|
||||
'deleteable',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $with = [
|
||||
'childs',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function parent()
|
||||
{
|
||||
return $this->hasOne(static::class, 'id', 'parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function childs()
|
||||
{
|
||||
return $this->hasMany(static::class, 'parent_id', 'id')
|
||||
->with('childs')
|
||||
->orderBy('position');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function permissions()
|
||||
{
|
||||
return $this->belongsToMany(Permission::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function roles()
|
||||
{
|
||||
return $this->belongsToMany(Role::class);
|
||||
}
|
||||
}
|
||||
@@ -63,31 +63,4 @@ class User extends Authenticatable
|
||||
protected $appends = [
|
||||
'profile_photo_url',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function menus()
|
||||
{
|
||||
return Menu::where(function (Builder $query) {
|
||||
$this->roles->each(function (Role $role) use ($query) {
|
||||
$query->orWhereHas('permissions', function (Builder $query) use ($role) {
|
||||
$query->whereIn('permissions.id', $role->permissions->pluck('id')->toArray());
|
||||
});
|
||||
});
|
||||
|
||||
$query->orWhereHas('roles', function (Builder $query) {
|
||||
$query->whereIn('roles.id', $this->roles->pluck('id')->toArray());
|
||||
});
|
||||
|
||||
$query->orWhereHas('permissions', function (Builder $query) {
|
||||
$query->whereIn('permissions.id', $this->permissions->pluck('id')->toArray());
|
||||
});
|
||||
})
|
||||
->orWhere(function (Builder $query) {
|
||||
$query->orDoesntHave('permissions');
|
||||
$query->orDoesntHave('roles');
|
||||
})
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user