feat(menus): assign event routes to OnTicket
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
private const TENANT_CODE = 'onticket';
|
||||
|
||||
private const EVENT_MENUS = [
|
||||
'event.index' => [
|
||||
'label' => 'Eventos',
|
||||
'route' => '/',
|
||||
],
|
||||
'event.detail' => [
|
||||
'label' => 'Detalle de evento',
|
||||
'route' => '/evento/:id',
|
||||
],
|
||||
];
|
||||
|
||||
private const EXCLUDED_MENU_CODES = [
|
||||
'product.detail',
|
||||
'help',
|
||||
'help.faq',
|
||||
'help.contact',
|
||||
'help.payment-methods',
|
||||
'help.shipping',
|
||||
'help.terms-and-conditions',
|
||||
'adminapp.tickets',
|
||||
'adminapp.fiesta-futbol-infantil.entradas',
|
||||
'adminapp.fiesta-futbol-infantil.alojamientos',
|
||||
'adminapp.fiesta-futbol-infantil.merchandising',
|
||||
'adminapp.fiesta-futbol-infantil.comida',
|
||||
'adminapp.desfile.entradas',
|
||||
];
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
$now = now();
|
||||
|
||||
DB::transaction(function () use ($now): void {
|
||||
foreach (self::EVENT_MENUS as $code => $menu) {
|
||||
DB::table('menues')->updateOrInsert(
|
||||
['code' => $code],
|
||||
[
|
||||
'label' => $menu['label'],
|
||||
'parent_menu_code' => null,
|
||||
'content_type' => 'dynamic',
|
||||
'static_content_schema' => null,
|
||||
'route' => $menu['route'],
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
DB::table('roles')
|
||||
->whereIn('codigo', ['admin', 'adminapp', 'user'])
|
||||
->pluck('codigo')
|
||||
->each(function (string $roleCode): void {
|
||||
foreach (array_keys(self::EVENT_MENUS) as $menuCode) {
|
||||
DB::table('roles_menues')->updateOrInsert([
|
||||
'rol_codigo' => $roleCode,
|
||||
'menu_codigo' => $menuCode,
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
if (! DB::table('tenants')->where('codigo', self::TENANT_CODE)->exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::table('menues')
|
||||
->whereNotIn('code', self::EXCLUDED_MENU_CODES)
|
||||
->pluck('code')
|
||||
->each(function (string $menuCode) use ($now): void {
|
||||
DB::table('tenants_menues')->updateOrInsert(
|
||||
[
|
||||
'tenant_code' => self::TENANT_CODE,
|
||||
'menu_code' => $menuCode,
|
||||
],
|
||||
[
|
||||
'static_content' => null,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
],
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
DB::transaction(function (): void {
|
||||
$assignedMenuCodes = DB::table('menues')
|
||||
->whereNotIn('code', self::EXCLUDED_MENU_CODES)
|
||||
->pluck('code');
|
||||
|
||||
DB::table('tenants_menues')
|
||||
->where('tenant_code', self::TENANT_CODE)
|
||||
->whereIn('menu_code', $assignedMenuCodes)
|
||||
->delete();
|
||||
|
||||
DB::table('roles_menues')
|
||||
->whereIn('menu_codigo', array_keys(self::EVENT_MENUS))
|
||||
->delete();
|
||||
|
||||
DB::table('menues')
|
||||
->whereIn('code', array_keys(self::EVENT_MENUS))
|
||||
->delete();
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user