| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace App\Commands;
- use App\Models\Permission;
- use App\Models\UserTypePermission;
- use Illuminate\Console\Command;
- use Database\Seeders\PermissionSeeder;
- use Database\Seeders\UserTypePermissionSeeder;
- class RefreshPermissions extends Command
- {
- public function __construct(
- protected PermissionSeeder $permissionSeeder,
- protected UserTypePermissionSeeder $userTypePermissionSeeder,
- ) {
- parent::__construct();
- }
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'permissions:refresh';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Refresh all permissions and user type permissions';
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function handle()
- {
- $this->info('Starting permissions refresh...');
- try {
- // Run the Permission seeder
- $this->info('Running Permission seeder...');
- Permission::truncate();
- $this->permissionSeeder->run();
- $this->info('Permission seeder completed successfully.');
- // Run the UserTypePermission seeder
- $this->info('Running UserTypePermission seeder...');
- UserTypePermission::truncate();
- $this->userTypePermissionSeeder->run();
- $this->info('UserTypePermission seeder completed successfully.');
- $this->info('Permissions refresh completed successfully!');
- return Command::SUCCESS;
- } catch (\Exception $e) {
- $this->error('An error occurred while refreshing permissions:');
- $this->error($e);
- return Command::FAILURE;
- }
- }
- }
|