App\Services\Repositories\OptionRepository::save PHP Method

save() public method

Do really save modified options to database.
public save ( ) : void
return void
    public function save()
    {
        $this->itemsModified = array_unique($this->itemsModified);
        try {
            foreach ($this->itemsModified as $key) {
                if (!DB::table('options')->where('option_name', $key)->first()) {
                    DB::table('options')->insert(['option_name' => $key, 'option_value' => $this[$key]]);
                } else {
                    DB::table('options')->where('option_name', $key)->update(['option_value' => $this[$key]]);
                }
            }
            // clear the list
            $this->itemsModified = [];
        } catch (QueryException $e) {
            return;
        }
    }

Usage Example

 /**
  * Persist the currently enabled plugins.
  *
  * @param array $enabled
  */
 protected function setEnabled(array $enabled)
 {
     $enabled = array_values(array_unique($enabled));
     $this->option->set('plugins_enabled', json_encode($enabled));
     // ensure to save options
     $this->option->save();
 }