/** * @param int $publicId * * @return Order */ public function byPublicId(int $publicId) : Order { /** @var Order $order */ $order = $this->orderResource->with(self::DEFAULT_RELATIONS)->where('id', '=', Order::privateId($publicId))->first(); if ($order instanceof Order) { return $order; } return new Order(); }
public function withRelatedCriterion(QueryBuilder $query) { if ($this->related === null) { throw new \RuntimeException('No relationships defined in the repository. Eloquent does ' . 'not support reading relationships from the Model. Related ' . 'models must be defined in the $related property of the ' . 'repository.'); } return $query->with($this->related); }
/** * Add relationships to the query builder to eager load * * @return $this */ protected function eagerLoad() { foreach ($this->with as $relation) { $this->query->with($relation); } return $this; }
/** * Returns a new Issue table. * * @param Issue|Builder $issue * @param array $with * @param Closure $closure * * @return \Orchestra\Contracts\Html\Builder */ public function table($issue, array $with = ['users', 'labels'], Closure $closure = null) { $label = request('label'); // Filter issues with the specified request label. $issue->with($with)->label($label)->latest(); return $this->table->of('issues', function (TableGrid $table) use($issue, $closure) { if ($closure instanceof Closure) { $table = call_user_func($closure, $table, $issue); } else { $table->with($issue)->paginate($this->perPage); } $table->sortable(['title', 'description', 'created_at']); $table->searchable(['title', 'description']); $table->column('status', function (Column $column) { $column->label = ''; $column->value = function (Issue $issue) { return $issue->present()->statusIcon(); }; $column->attributes(function () { return ['width' => '30']; }); }); $table->column('title', function (Column $column) { return $this->tableTitle($column); }); }); }
/** * Apply resource options to a query builder * @param Builder $query * @param array $options * @return Builder */ protected function applyResourceOptions(Builder $query, array $options = []) { if (!empty($options)) { extract($options); if (isset($includes)) { if (!is_array($includes)) { throw new InvalidArgumentException('Includes should be an array.'); } $query->with($includes); } if (isset($filter_groups)) { $filterJoins = $this->applyFilterGroups($query, $filter_groups); } if (isset($sort)) { if (!is_array($sort)) { throw new InvalidArgumentException('Sort should be an array.'); } if (!isset($filterJoins)) { $filterJoins = []; } $sortingJoins = $this->applySorting($query, $sort, $filterJoins); } if (isset($limit)) { $query->limit($limit); } if (isset($page)) { $query->offset($page * $limit); } } return $query; }
/** * Returns all the registered users. * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ public function scopeWithUserMessages(Builder $query) { return $query->with(['user.messages' => function ($query) { return $query->whereReceptorId(Auth::user()->id)->orderBy('created_at', 'asc'); }, 'user.receivedMessages' => function ($query) { return $query->whereAuthorId(Auth::user()->id)->orderBy('created_at', 'asc'); }]); }
/** * 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; }
/** * Retrive all notifications, not read * in first. * You can also limit the number of * Notifications if you don't, it will get all * * @param $to_id * @param $entity * @param null $limit * @param int|null $paginate * @param string $orderDate * @param Closure $filterScope * @return mixed */ public function getAll($to_id, $entity, $limit = null, $paginate = null, $orderDate = 'desc', Closure $filterScope = null) { $query = $this->notification->with('body', 'from')->wherePolymorphic($to_id, $entity)->orderBy('read', 'ASC')->orderBy('created_at', $orderDate); $query = $this->applyFilter($filterScope, $query); if (is_int(intval($paginate)) && $paginate) { return $query->paginate($limit); } return $query->get(); }
/** * Retrive all notifications, not read * in first. * You can also limit the number of * Notifications if you don't, it will get all * * @param $to_id * @param $entity * @param null $limit * @param bool $paginate * @param string $orderDate * @return mixed */ public function getAll($to_id, $entity, $limit = null, $paginate = false, $orderDate = 'desc') { $result = $this->notification->with('body', 'from')->wherePolymorphic($to_id, $entity)->orderBy('read', 'ASC')->orderBy('created_at', $orderDate); // if the limit is set if (!is_null($limit)) { $result->limit($limit); } return $result->get(); }
/** * @return $this */ protected function eagerLoadRelations() { if (isset($this->with)) { foreach ($this->with as $relation) { $this->model->with($relation); } } return $this; }
/** * {@inheritdoc} */ public function constraintBuilder(EloquentBuilder $builder, array $options) { if ($relations = $this->eagerLoads(array_get($options, 'simple'))) { $builder->with($relations); } $query = $builder->getQuery(); if ($value = array_get($options, 'order', $this->defaultOrder)) { $this->order($query, $value); } }
/** * @param Builder|\Illuminate\Database\Query\Builder $builder * @param null $columns * * @return mixed */ public function scopeWithRevisionsWithoutData($builder, $columns = null) { $columns = $columns ?: ['id', 'event', 'revisionable_type', 'revisionable_id', 'user_id', 'created_at', 'updated_at']; $builder->with(['revisions' => function ($q) use($columns) { /** @var Builder|\Illuminate\Database\Query\Builder $q */ $q->select($columns); $q->with('user'); }]); return $builder; }
/** * This scope eager loads the translations for the default and the fallback locale only. * We can use this as a shortcut to improve performance in our application. * * @param Builder $query */ public function scopeWithTranslation(Builder $query) { $query->with(['translations' => function ($query) { $query->where(function ($query) { $query->where($this->getTranslationsTable() . '.' . $this->getLocaleKey(), $this->locale()); if ($this->useFallback()) { return $query->orWhere($this->getTranslationsTable() . '.' . $this->getLocaleKey(), $this->getFallbackLocale($this->locale()))->orWhere($this->getTranslationsTable() . '.' . $this->getLocaleKey(), $this->getFallbackLocale()); } }); }]); }
/** * Otimiza as query do Eloquent adicionando * Eager Loading do Eloquent * @param string cidade,cidade.estado * @return \Eloquent */ protected function scopeWithEmbed($embed = null) { $embed = is_null($embed) ? \Input::get('include') : $embed; $requestedEmbeds = explode(',', $embed); $possibleRelationships = (array) $this->model->relationships; $eagerLoad = array_values(array_intersect($possibleRelationships, $requestedEmbeds)); if (!empty($eagerLoad)) { \Log::info($eagerLoad); $this->query->with($eagerLoad); } return $this; }
/** * Retrive all notifications, in a stack. * You can also limit the number of * Notifications if you don't, it will get all. * * @param $stackId * @param null $limit * @param int|null $paginate * @param string $orderDate * @param Closure $filterScope * @return mixed */ public function getStack($stackId, $limit = null, $paginate = null, $orderDate = 'desc', Closure $filterScope = null) { $query = $this->notification->with('body', 'from', 'to')->byStack($stackId)->orderBy('read', 'ASC')->orderBy('created_at', $orderDate); if ($limit && !$paginate) { $query->limit($limit); } $query = $this->applyFilter($filterScope, $query); if (is_int(intval($paginate)) && $paginate) { return $query->paginate($limit); } return $query->get(); }
public function apply(Builder $builder) { $select = ['Simulation.*', 'Power_Generator.Modality_Id']; $builder->with(['Combination.NumericalModel', 'Combination.Protocol', 'Combination.PowerGenerator', 'Combination.PowerGenerator.Modality'])->leftJoin('Power_Generator', 'Power_Generator.Id', '=', 'Combination.Power_Generator_Id')->leftJoin('Combination', 'Combination.Combination_Id', '=', 'Simulation.Combination_Id'); if (Config::get('gosmart.integrated_patient_database')) { $builder->leftJoin('ItemSet as SimulationItem', 'SimulationItem.Id', '=', 'Simulation.Id')->leftJoin('ItemSet as PatientItem', 'PatientItem.Id', '=', 'Simulation.Patient_Id')->leftJoin('ItemSet_Patient', 'ItemSet_Patient.Id', '=', 'Simulation.Patient_Id')->leftJoin('ItemSet_VtkFile as SimulatedLesionSurface', 'SimulatedLesionSurface.Simulation_Id', '=', 'Simulation.Id')->leftJoin('ItemSet_VtuFile as SimulatedLesionVolume', 'SimulatedLesionVolume.Simulation_Id', '=', 'Simulation.Id')->leftJoin('ItemSet_Segmentation', function ($leftJoin) { $leftJoin->on('ItemSet_Segmentation.Patient_Id', '=', 'Simulation.Patient_Id'); $leftJoin->on('ItemSet_Segmentation.State', '=', DB::raw('3')); $leftJoin->on('ItemSet_Segmentation.SegmentationType', '=', DB::raw(SegmentationTypeEnum::Lesion)); })->leftJoin('ItemSet_VtkFile as LesionFile', 'LesionFile.Segmentation_Id', '=', 'ItemSet_Segmentation.Id')->leftJoin('AspNetUsers as Clinician', 'Clinician.Id', '=', 'ItemSet_Patient.AspNetUsersId'); $select = array_merge($select, ['SimulationItem.CreationDate as creationDate', 'LesionFile.Id as SegmentedLesionId', 'Clinician.Id as ClinicianId', 'Clinician.UserName as ClinicianUserName', 'ItemSet_Patient.Alias as PatientAlias', 'ItemSet_Patient.Description as PatientDescription', 'SimulatedLesionSurface.Id as SimulatedLesionSurfaceId', 'SimulatedLesionVolume.Id as SimulatedLesionVolumeId']); } $builder->select($select); }
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']); } } }
/** * Parse the with parameter. * * @param string $params * @return void */ protected function parseWith($params) { $with = explode(',', $params); $with = in_array('*', $this->withable) ? $with : array_only($with, $this->withable); foreach ($this->additionalSorts as $sort => $direction) { $parts = explode('.', $sort); $realKey = array_pop($parts); $relation = implode('.', $parts); if (in_array($relation, $with)) { $this->builder->with([$relation => function ($query) use($realKey, $direction) { $query->orderBy($realKey, $direction); }]); if (($key = array_search($relation, $with)) !== false) { unset($with[$key]); } } } if (!empty($with)) { $this->builder->with($with); } $this->with = $this->builder->getEagerLoads(); }
/** * Master query for getting a list of records * * @param Builder $query The query to start with. * * @return Builder */ public static function listing(Builder $query) { return $query->with('client')->orderByRaw('LOWER(projects.name) ASC'); }
public static function buildFormQuery(Builder $query) { $query->with('posts'); }
public function scopeStructured(Builder $builder) { $builder->with(['childs'])->whereNull('parent_id'); }
/** * Scope a query to only include staff that are in charge of all centres that the specified staff are in charge of. * * @param \Illuminate\Database\Eloquent\Builder $query the query to staff to be scoped * @param \App\Staff $staff the staff to be scoped * @return \Illuminate\Database\Eloquent\Builder */ public function scopeOfCentres($query, $staff) { $query->with('centres')->select('staff.*')->join('centre_staff', function ($join) { $join->on('staff.staff_id', '=', 'centre_staff.staff_id'); })->whereIn('centre_staff.centre_id', $staff->centres->lists('centre_id'))->distinct(); }
/** * @param Builder $query * @param DocumentInterface $document */ public function querySelectColumn(Builder $query, DocumentInterface $document) { $query->with($this->getRelationName()); }
/** * @param int $optionId * * @return ProductOption */ public function loadById(int $optionId) { return $this->optionResource->with('product')->where('id', '=', $optionId)->first(); }
/** * Get online galleries. * * @param Builder $query * * @return Builder $query */ public function scopeWithOnlineGalleries(Builder $query) { if (!method_exists($this, 'galleries')) { return $query; } return $query->with(['galleries.files', 'galleries' => function (MorphToMany $query) { $query->online(); }]); }
/** * Find subquery fields. * * @param Builder $query * @param string $relation * @param array $columns * * @return Builder */ public function scopeWithCertain($query, $relation, array $columns) { return $query->with([$relation => function ($query) use($columns) { $query->select($columns); }]); }
/** * Get online galleries. * * @param Builder $query * * @return Builder $query */ public function scopeWithOnlineGalleries(Builder $query) { if (!method_exists($this, 'galleries')) { return $query; } return $query->with(['galleries.translations', 'galleries.files.translations', 'galleries' => function (MorphToMany $query) { $query->whereHas('translations', function (Builder $query) { $query->where('status', 1); $query->where('locale', config('app.locale')); }); }]); }
/** * @codeCoverageIgnore * Automatically includes the 'with' parameters to get relevant related * objects. * * @param EloquentBuilder $query */ public function scopeWithRelevantData(EloquentBuilder $query) { $query->with(['transactions' => function (HasMany $q) { $q->orderBy('amount', 'ASC'); }, 'transactionType', 'transactionCurrency', 'budgets', 'categories', 'transactions.account.accounttype', 'bill']); }
/** * Set Relationships. * * @param array $with Relationships * * @return \Illuminate\Database\Eloquent\Builder */ public function make(array $with = []) { return $this->model->with($with); }
/** * @param Builder $builder * @param Array $added * @return Builder */ protected function applyEagerLoads($builder, $added = []) { return $builder->with($this->eagerLoads + $added); }