Sebpro\ArtisanExt\Commands\ExtDBHost::handle PHP Метод

handle() публичный Метод

Execute the console command.
public handle ( ) : void
Результат void
    public function handle()
    {
        $old_db_host = $this->laravel['config']['database.connections.' . $this->laravel['config']['database.default'] . '.host'];
        $file = base_path('.env');
        if (file_exists($file)) {
            file_put_contents($file, str_replace('DB_HOST=' . $old_db_host, 'DB_HOST=' . $this->argument('databasehost'), file_get_contents($file)));
            if ($this->option('check')) {
                $this->info('The database host has been changed ' . 'successfully to: ' . $this->argument('databasehost'));
                $this->laravel['config']['database.connections.' . $this->laravel['config']['database.default'] . '.host'] = $this->argument('databasehost');
                try {
                    ArtisanExt::checkDb();
                    return $this->info('Succesfully connected to the database.');
                } catch (\PDOException $e) {
                    return $this->error('Failed to connect to the database.');
                }
            }
            return $this->info('The database host has been changed ' . 'successfully to: ' . $this->argument('databasehost'));
        }
        return $this->error('The .env configuration file is missing.');
    }