/**
  * Find a configuration by it's key
  * or return a new instance.
  *
  * @param $key
  * @param $scope
  * @return ConfigurationInterface
  */
 public function findByKeyAndScopeOrNew($key, $scope)
 {
     if (!($configuration = $this->model->where('key', $key)->where('scope', $scope)->first())) {
         $configuration = $this->model->newInstance();
         $configuration->setKey($key);
         $configuration->setScope($scope);
     }
     return $configuration;
 }
 /**
  * Set a configuration value.
  *
  * @param $key
  * @param $scope
  * @param $value
  * @return $this
  */
 public function set($key, $scope, $value)
 {
     $configuration = $this->model->where('scope', $scope)->where('key', $key)->first();
     if (!$configuration) {
         $configuration = $this->model->newInstance();
         $configuration->key = $key;
         $configuration->scope = $scope;
     }
     if (!($field = config(str_replace('::', '::configuration/configuration.', $key)))) {
         $field = config(str_replace('::', '::configuration.', $key));
     }
     if (is_string($field)) {
         $field = ['type' => $field];
     }
     $type = app(array_get($field, 'type'));
     $modifier = $type->getModifier();
     if ($modifier instanceof FieldTypeModifier) {
         $value = $modifier->modify($value);
     }
     $configuration->value = $value;
     $configuration->save();
     return $this;
 }