0% found this document useful (0 votes)
3 views

SetSettingCommand.php

no

Uploaded by

Lakshmi Bhaskar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

SetSettingCommand.php

no

Uploaded by

Lakshmi Bhaskar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

<?

php

namespace App\Console\Commands;

use Exception;
use Illuminate\Console\Command;

class SetSettingCommand extends Command


{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'settings:set {class : Settings Class (Example:
GeneralSettings)} {key : Unique setting key} {value : Value to set}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Set value of a setting key.';

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{

$class = $this->argument('class');
$key = $this->argument('key');
$value = $this->argument('value');

try {
$settings_class = "App\\Settings\\$class";
$settings = new $settings_class();

$settings->$key = $value;

$settings->save();

$this->info("Successfully updated '$key'.");


} catch (\Throwable $th) {
$this->error('Error: ' . $th->getMessage());
return Command::FAILURE;
}

return Command::SUCCESS;
}
}

You might also like