diff --git a/src/Commands/FilaChatCommand.php b/src/Commands/FilaChatCommand.php index 8cd448f..6785a6b 100644 --- a/src/Commands/FilaChatCommand.php +++ b/src/Commands/FilaChatCommand.php @@ -3,17 +3,57 @@ namespace JaOcero\FilaChat\Commands; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Artisan; +use JaOcero\FilaChat\Enums\RoleType; +use JaOcero\FilaChat\Models\FilaChatRole; class FilaChatCommand extends Command { - public $signature = 'filachat'; + public $signature = 'filachat::install'; - public $description = 'My command'; + public $description = 'Setup the FilaChat plugin'; public function handle(): int { + $this->info('Starting FilaChat setup...'); + $this->publishAssets(); + $this->runMigrations(); + $this->seedRoles(); $this->comment('All done'); return self::SUCCESS; } + + protected function publishAssets() + { + $this->info('Publishing assets...'); + Artisan::call('vendor:publish', [ + '--provider' => 'JaOcero\FilaChat\FilaChatServiceProvider', + '--tag' => ['migrations', 'config'], + ]); + $this->info('Assets published.'); + } + + protected function runMigrations() + { + $this->info('Running migrations...'); + Artisan::call('migrate'); + $this->info('Migrations completed.'); + } + + protected function seedRoles() + { + $this->info('Seeding roles...'); + + $roles = [ + ['name' => RoleType::AGENT->value], + ['name' => RoleType::USER->value], + ]; + + foreach ($roles as $role) { + FilaChatRole::firstOrCreate($role); + } + + $this->info('Roles seeded.'); + } } diff --git a/src/FilaChatServiceProvider.php b/src/FilaChatServiceProvider.php index abea0a6..76bf750 100644 --- a/src/FilaChatServiceProvider.php +++ b/src/FilaChatServiceProvider.php @@ -32,11 +32,7 @@ public function configurePackage(Package $package): void $package->name(static::$name) ->hasCommands($this->getCommands()) ->hasInstallCommand(function (InstallCommand $command) { - $command - ->publishConfigFile() - ->publishMigrations() - ->askToRunMigrations() - ->askToStarRepoOnGitHub('199ocero/filachat'); + $command->askToStarRepoOnGitHub('199ocero/filachat'); }); $configFileName = $package->shortName();