. */ namespace App\Console\Commands\Spaces; use App\Space; use Illuminate\Console\Command; class CreateUpdate extends Command { protected $signature = 'spaces:create-update {sip_domain} {host} {name} {--super}'; protected $description = 'Create a Space'; public function handle() { $this->info('Your are creating or updating a Space in the database'); if (empty(config('app.root_host'))) { $this->error('The environnement variable APP_ROOT_HOST doesn\'t seems to be set'); } if (!str_ends_with($this->argument('host'), config('app.root_host'))) { $this->error('The provided host doesn\'t seems to ends with ' . config('app.root_host')); } $space = Space::where('domain', $this->argument('sip_domain'))->firstOrNew(); $space->host = $this->argument('host'); $space->domain = $this->argument('sip_domain'); $space->name = $this->argument('name'); $space->exists ? $this->info('The domain already exists, updating it') : $this->info('A new domain will be created'); $space->super = (bool)$this->option('super'); $space->super ? $this->info('Set as a super domain') : $this->info('Set as a normal domain'); $space->save(); return Command::SUCCESS; } }