App\Console\Commands\SettingSetCommand::handle PHP Method

handle() public method

Execute the console command.
public handle ( ) : mixed
return mixed
    public function handle()
    {
        try {
            if ($key = $this->argument('key')) {
                $message = "";
                $value = $this->argument('value');
                $encrypt = $this->option('encrypt');
                if (Str::isNullOrEmptyString($value)) {
                    if ($encrypt) {
                        $value = $this->secret('Enter secret value:');
                        $message = "Setting [{$key}] set to encrypted value.";
                    } else {
                        $value = $this->ask('Enter value:');
                        $message = "Setting [{$key}] set to [{$value}].";
                    }
                }
                Setting::set($key, $value, $encrypt);
                Setting::save();
                $this->info($message);
            } else {
                $this->error("Missing 'key' argument.");
            }
        } catch (\Exception $ex) {
            $this->error("Exception: " . $ex->getMessage());
            $this->error("Stack trace: " . $ex->getTraceAsString());
        }
    }
SettingSetCommand