fix seeder
parent
d3288c7cd4
commit
d25ebb2d09
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CreateAtasCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:generate-atas';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
|
||||
$this->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.');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class CreateFreshCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:generate-fresh';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->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.');
|
||||
}
|
||||
}
|
|
@ -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.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class GenerateAtasSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$classes = [
|
||||
RoleSeeder::class,
|
||||
];
|
||||
foreach ($classes as $class) $this->call($class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class GenerateFreshSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$classes = [
|
||||
UserSeeder::class,
|
||||
KasirSeeder::class,
|
||||
];
|
||||
foreach ($classes as $class) $this->call($class);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue