diff --git a/app/Console/Commands/CreateAtasCommand.php b/app/Console/Commands/CreateAtasCommand.php new file mode 100644 index 0000000..5271c8b --- /dev/null +++ b/app/Console/Commands/CreateAtasCommand.php @@ -0,0 +1,74 @@ +info('Migration started..'); + + $migrate = Artisan::call('migrate'); + + $this->info('Migrate successfully.'); + + $this->info('Truncate started..'); + // Nonaktifkan constraint + DB::statement('SET FOREIGN_KEY_CHECKS=0;'); + + $this->info('Foreign key check disabled.'); + + DB::statement('TRUNCATE table roles'); + $this->info('Truncate roles successfully.'); + DB::statement('TRUNCATE table model_has_roles'); + $this->info('Truncate model_has_roles successfully.'); + DB::statement('TRUNCATE table model_has_permissions'); + $this->info('Truncate model_has_permissions successfully.'); + DB::statement('TRUNCATE table permissions'); + $this->info('Truncate permissions successfully.'); + DB::statement('TRUNCATE table role_has_permissions'); + $this->info('Truncate role_has_permissions successfully.'); + // Aktifkan kembali constraint + DB::statement('SET FOREIGN_KEY_CHECKS=1;'); + $this->info('Foreign key check enabled.'); + $this->info('Truncate successfully.'); + + $this->info('Permission started..'); + Artisan::call('route:clear'); + $this->info('Route cache cleared successfully.'); + Artisan::call('permission:cache-reset'); + $this->info('Permission cache reset successfully.'); + Artisan::call('permission:create-permission-routes'); + $this->info('Permission successfully.'); + + $this->info('Seeder started..'); + Artisan::call('db:seed', [ + '--class' => 'GenerateAtasSeeder', + '--force' => true + ]); + $this->info('Seeder successfully.'); + } +} diff --git a/app/Console/Commands/CreateFreshCommand.php b/app/Console/Commands/CreateFreshCommand.php new file mode 100644 index 0000000..8345e10 --- /dev/null +++ b/app/Console/Commands/CreateFreshCommand.php @@ -0,0 +1,46 @@ +info('Migration started..'); + + $migrate = Artisan::call('migrate:fresh --seed'); + + $this->info('Migrate successfully.'); + + $this->info('Permission started..'); + Artisan::call('permission:create-permission-routes'); + $this->info('Permission successfully.'); + + $this->info('Seeder started..'); + Artisan::call('db:seed', [ + '--class' => 'GenerateFreshSeeder', + '--force' => true + ]); + $this->info('Seeder successfully.'); + } +} diff --git a/app/Console/Commands/CreateRoutePermissionCommand.php b/app/Console/Commands/CreateRoutePermissionCommand.php index 7274239..fcef81e 100644 --- a/app/Console/Commands/CreateRoutePermissionCommand.php +++ b/app/Console/Commands/CreateRoutePermissionCommand.php @@ -42,10 +42,11 @@ class CreateRoutePermissionCommand extends Command } if (is_null($permission)) { permission::create(['name' => $data, 'group_name' => $first_group, 'desc' => $comment]); + $this->info('Permission routes ' . $route->getName() . ' added successfully.'); } } } - $this->info('Permission routes added successfully.'); + $this->info('All Permission routes added successfully.'); } } diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index c27babb..bdab3a1 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -25,14 +25,14 @@ class RedirectIfAuthenticated $role = Auth::user()->role; switch ($role[0]->name) { case 'Admin': - return '/dashboard'; + return redirect('/dashboard'); break; case 'Kasir': - return '/transaksi'; + return redirect('/transaksi'); break; default: - return '/transaksi'; + return redirect('/transaksi'); break; } } diff --git a/database/seeders/GenerateAtasSeeder.php b/database/seeders/GenerateAtasSeeder.php new file mode 100644 index 0000000..45bbc7c --- /dev/null +++ b/database/seeders/GenerateAtasSeeder.php @@ -0,0 +1,22 @@ +call($class); + } +} diff --git a/database/seeders/GenerateFreshSeeder.php b/database/seeders/GenerateFreshSeeder.php new file mode 100644 index 0000000..eaedddf --- /dev/null +++ b/database/seeders/GenerateFreshSeeder.php @@ -0,0 +1,21 @@ +call($class); + } +} diff --git a/database/seeders/PermissionSeeder.php b/database/seeders/PermissionSeeder.php index c5e1419..f752f6f 100644 --- a/database/seeders/PermissionSeeder.php +++ b/database/seeders/PermissionSeeder.php @@ -13,10 +13,8 @@ class PermissionSeeder extends Seeder public function run(): void { $classes = [ - UserSeeder::class, - KasirSeeder::class, - // AddRoles::class, - // RoleSeeder::class, + GenerateAtasSeeder::class, + // GenerateFreshSeeder::class, ]; foreach ($classes as $class) $this->call($class); } diff --git a/database/seeders/RoleSeeder.php b/database/seeders/RoleSeeder.php index 429209f..18741ca 100644 --- a/database/seeders/RoleSeeder.php +++ b/database/seeders/RoleSeeder.php @@ -17,6 +17,7 @@ class RoleSeeder extends Seeder */ public function run(): void { + // admin $role = Role::create(['name' => 'Admin']); $permissions = Permission::pluck('id', 'id')->all(); @@ -27,6 +28,7 @@ class RoleSeeder extends Seeder $user->assignRole([$role->id]); + // kasir $role = Role::create(['name' => 'Kasir']); $permissions = Permission::pluck('id', 'id')->all();