public function getRoleByName($roleName) { $query = $this->model->with('roles')->whereHas('roles', function ($q) use($roleName) { $q->where('name', '=', $roleName); })->get(); return $query; }
public function with($relations) { if (is_string($relations)) { $relations = func_get_args(); } $this->model = $this->model->with($relations); return $this; }
/** * @return $this */ protected function eagerLoading() { if (!is_null($this->relations)) { $this->model = $this->model->with($this->relations); } return $this; }
/** * Get instance of model by column * * @param mixed $term search term * @param string $column column to search * @return \Illuminate\Database\Eloquent\Collection */ public function getCollectionByColumn($term, $column = 'slug') { $query = function () use($term, $column) { return $this->model->with($this->requiredRelationships)->where($column, '=', $term)->get(); }; return $this->doQuery($query); }
/** * Load relations * * @param array|string $relations * @return $this */ public function with($relations) { /** * Save to conditons. */ $this->addCondition('with', $relations); $this->model = $this->model->with($relations); return $this; }
/** * Display a paginated list of the resource. * * @param Paginator * @return Response */ public function index($resources = null) { // Get the resources if they have not been provided by the child class if (is_null($resources)) { $resources = $this->resource->with($this->with)->paginate(); } // Load view return view('resource.index', ['title' => $this->title ?: $this->resource->plural, 'subtitle' => $this->subtitle ?: _('Index'), 'resources' => $resources]); }
private function buildQuery() { $this->query = app(get_class($this->model)); if (!empty($this->fields)) { $this->query = $this->query->select($this->fields); } if (!empty($this->relations)) { $this->relations = array_unique($this->relations); $this->query = $this->query->with($this->relations); } if (!empty($this->per_page)) { $this->query = $this->query->take($this->per_page); } if (count($this->conditions)) { foreach ($this->conditions as $condition) { $this->query = $this->query->where($condition['column'], $condition['operator'], $condition['value'], $condition['boolean']); } } }
/** * Find instance with relation by id. * * @param integer $id * @param string|array $relations * * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection */ public function findByIdWithRelation($id, $relations) { return $this->model->with($relations)->findOrFail($id); }
/** * returns the query builder with eager loading, or the model itself * * @return Builder|Model */ protected function make() { return $this->model->with($this->with); }
/** * Load relations. * * @param array|string $relations * * @return $this */ public function with($relations) { $this->model = $this->model->with($relations); return $this; }
/** * Returns a range of records bounded by pagination parameters. * * @param int limit * @param int $offset * * @return \Illuminate\Database\Eloquent\Collection */ public function page($limit = 10, $offset = 0, array $relations = [], $orderBy = 'updated_at', $sorting = 'desc') { return $this->model->with($relations)->take($limit)->skip($offset)->orderBy($orderBy, $sorting)->get(); }
/** * @return \Illuminate\Database\Eloquent\Model */ public function getModelWith() { return $this->model->with($this->with); }
/** * Load relations. * * @param string|array $relation * * @return this */ public function with($relations) { $relations = is_array($relations) ? $relations : func_get_args(); $this->model = $this->model->with($relations); return $this; }
/** * @param $id * @param array|null $with * @return mixed */ public function find($id, $with = []) { return $this->model->with($with)->findOrFail($id); }
/** * Apply any relationships to eager-load. * * @param Builder|Model $query * @return Builder|Model */ protected function applyRelations($query) { if (!empty($this->relations)) { return $query->with($this->relations); } return $query; }
/** * Retrieves a single page of records with related records * * @param string $related * @param int $perPage * @return Illuminate\Pagination\Paginator an instance of paginator. */ public function getbyPageWith($related, $perPage = self::PAGE) { return $this->model->with($related)->paginate($perPage); }
/** * Return data ordered by field * @param string $field * @param string $order */ public function orderBy($field = 'created_at', $order = 'ASC') { return $this->model->with($this->relations)->orderBy($field, $order)->get(); }
/** * @param Model $model * @param Repository $repository * * @return \Illuminate\Database\Eloquent\Builder|static */ public function apply(Model $model, Repository $repository) { return $model->with($this->relations); }
/** * Make a new instance of the entity to query on */ public function make() { return $this->model->with($this->with); }
public function getConsultancyPosts() { return $this->model->with(['category', 'photos', 'author'])->select('posts.*')->leftJoin('categories', 'categories.id', '=', 'posts.category_id')->where('categories.name_en', '=', 'consultancy')->orderBy('posts.created_at', 'DESC')->paginate(10); }
public function make(array $with = array()) { return $this->model->with($with); }
/** * Make a new instance of the entity to query on * * @param array $with */ protected function make(array $with = array()) { return $this->model->with($with); }