feat(menus): add storefront category permissions

This commit is contained in:
2026-09-21 09:24:19 -03:00
parent c665222837
commit 9a14b8fbbd
3 changed files with 112 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
private const MENUS = [
'event.category' => [
'label' => 'Categoría de eventos',
'route' => '/eventos/categoria/:id',
],
'product.category' => [
'label' => 'Categoría de productos',
'route' => '/categoria/:id',
],
];
public function up(): void
{
$now = now();
DB::transaction(function () use ($now): void {
foreach (self::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::MENUS) as $menuCode) {
DB::table('roles_menues')->updateOrInsert([
'rol_codigo' => $roleCode,
'menu_codigo' => $menuCode,
]);
}
});
DB::table('tenants')
->pluck('codigo')
->each(function (string $tenantCode) use ($now): void {
$menuCode = $tenantCode === 'onticket' ? 'event.category' : 'product.category';
DB::table('tenants_menues')->updateOrInsert(
[
'tenant_code' => $tenantCode,
'menu_code' => $menuCode,
],
[
'static_content' => null,
'created_at' => $now,
'updated_at' => $now,
],
);
});
});
}
public function down(): void
{
DB::transaction(function (): void {
$menuCodes = array_keys(self::MENUS);
DB::table('tenants_menues')->whereIn('menu_code', $menuCodes)->delete();
DB::table('roles_menues')->whereIn('menu_codigo', $menuCodes)->delete();
DB::table('menues')->whereIn('code', $menuCodes)->delete();
});
}
};