/**
  * @param KeysInterface|DataInterface|ModelInterface $config
  * @return mixed
  */
 public function apply($config)
 {
     if (!($config instanceof KeysInterface && $config instanceof DataInterface && $config instanceof ModelInterface)) {
         return;
     }
     $keys = $config->keys();
     if (empty($keys)) {
         return;
     }
     $params = $config->data()->only($keys)->all();
     if (is_array($params) && count($params) > 0) {
         $config->model($config->model()->where($params));
     }
 }
示例#2
0
 /**
  * @param WithInterface|DataInterface|ModelInterface $config
  * @return mixed
  */
 public function apply($config)
 {
     if (!($config instanceof WithInterface && $config instanceof DataInterface && $config instanceof ModelInterface)) {
         return;
     }
     if ($config->with()->isEmpty()) {
         return;
     }
     $this->config = $config;
     $this->allowed = $config->with();
     foreach ($this->allowed as $key => $value) {
         if (is_numeric($key)) {
             $this->allowed->forget($key)->put($value, '*');
         }
     }
     foreach (explode('|', $config->data()->get('with', '')) as $with) {
         $parts = explode(':', $with);
         if (count($parts) == 0) {
             continue;
         }
         if (!$this->allowed->has($parts[0])) {
             continue;
         }
         $this->processWith($parts[0], isset($parts[1]) ? $parts[1] : '');
     }
     if (count($this->approved) > 0) {
         $config->model($config->model()->with($this->approved));
     }
 }
示例#3
0
 /**
  * @param OrdersInterface|DataInterface|ModelInterface $config
  * @return mixed
  */
 public function apply($config)
 {
     if (!($config instanceof OrdersInterface && $config instanceof DataInterface && $config instanceof ModelInterface)) {
         return;
     }
     if ($config->orders()->isEmpty()) {
         return;
     }
     $order = $config->orders()->first();
     if (($field = $config->data()->get('order', false)) && $config->orders()->contains($field)) {
         $order = $field;
     }
     $sort = $config->data()->get('sort') == 'desc' ? 'desc' : 'asc';
     $model = $config->model()->orderBy($order, $sort)->orderBy('id', $sort);
     //echo $model->toSql(); exit;
     $config->model($model);
 }
 /**
  * @param ColumnsInterface|DataInterface|ModelInterface $config
  * @return mixed
  */
 public function apply($config)
 {
     if (!($config instanceof ColumnsInterface && $config instanceof DataInterface && $config instanceof ModelInterface)) {
         return;
     }
     $allowed = $config->columns();
     if ($config instanceof OtherColumnsInterface) {
         $allowed = $allowed->merge($config->otherColumns()->all())->unique();
     }
     if ($allowed->count() == 0) {
         return;
     }
     if ($columns = $config->data()->get('columns', false)) {
         $columns = $columns == '*' ? $allowed->all() : $allowed->intersect(explode(',', $columns))->all();
     }
     if ($without = $config->data()->get('withoutColumns', false)) {
         $columns = $allowed->diff(explode(',', $without))->all();
     }
     $model = $columns && count($columns) > 0 ? $config->model()->select($columns) : $config->model()->select($config->columns()->all());
     //echo $model->toSql(); exit;
     $config->model($model);
 }
示例#5
0
 /**
  * @param RulesInterface|DataInterface|ModelInterface $config
  * @return mixed
  */
 public function apply($config)
 {
     if (!($config instanceof RulesInterface && $config instanceof DataInterface && $config instanceof ModelInterface)) {
         return;
     }
     if ($config->rules()->isEmpty()) {
         return;
     }
     $this->data = $config->data();
     $config->model($this->run($config->rules(), $config->model()));
 }