Пример #1
0
 /**
  * @param $include
  */
 public function with($include)
 {
     // include key
     if (!is_null($include)) {
         $relations = explode(',', $include);
         foreach ($relations as $relation) {
             // todo validate the nested relations
             $directRelation = explode('.', $relation)[0];
             if (in_array($directRelation, $this->relations)) {
                 $this->object = $this->object->with($relation);
             } else {
                 ParseHelper::throwException(102);
             }
         }
     }
 }
Пример #2
0
 function applyWith()
 {
     $with = $this->raw_with;
     foreach ($this->query_with as $path => $callbacks) {
         $with[$path] = function ($query) use($callbacks) {
             foreach ($callbacks as $c) {
                 $callback = Arr::get($c, 'callback');
                 $params = Arr::get($c, 'params', []);
                 call_user_func_array($callback, array_merge([$query], $params));
             }
         };
     }
     $tmp = [];
     ksort($with);
     foreach ($with as $path => $callback) {
         if ($path == $callback) {
             $tmp[] = $path;
         } else {
             $tmp[$path] = $callback;
         }
     }
     $this->model->with($tmp);
 }
 /**
  * Begin querying a model with eager loading.
  *
  * @param  array|string  $relations
  */
 public function with($relations)
 {
     $this->model->with($relations);
     return $this;
 }