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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('menus', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('parent_id')
|
||||
->nullable()
|
||||
->default(null);
|
||||
$table->string('name');
|
||||
$table->string('route_or_url')->default('#');
|
||||
$table->string('icon')
|
||||
->default('circle');
|
||||
$table->boolean('enable')
|
||||
->default(true);
|
||||
$table->integer('position');
|
||||
$table->json('actives')
|
||||
->default('[]');
|
||||
$table->boolean('deleteable')
|
||||
->default(true);
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('parent_id')
|
||||
->references('id')
|
||||
->on('menus')
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('menus');
|
||||
}
|
||||
};
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('menu_permission', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('menu_id')
|
||||
->constrained()
|
||||
->cascadeOnDelete();
|
||||
$table->foreignId('permission_id')
|
||||
->constrained()
|
||||
->cascadeOnDelete();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('menu_permission');
|
||||
}
|
||||
};
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('menu_role', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('menu_id')
|
||||
->constrained()
|
||||
->cascadeOnDelete();
|
||||
$table->foreignId('role_id')
|
||||
->constrained()
|
||||
->cascadeOnDelete();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('menu_role');
|
||||
}
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class MenuSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user