本文整理汇总了PHP中Illuminate\Database\Eloquent\Model::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::with方法的具体用法?PHP Model::with怎么用?PHP Model::with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Model
的用法示例。
在下文中一共展示了Model::with方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRoleByName
public function getRoleByName($roleName)
{
$query = $this->model->with('roles')->whereHas('roles', function ($q) use($roleName) {
$q->where('name', '=', $roleName);
})->get();
return $query;
}
示例2: with
public function with($relations)
{
if (is_string($relations)) {
$relations = func_get_args();
}
$this->model = $this->model->with($relations);
return $this;
}
示例3: eagerLoading
/**
* @return $this
*/
protected function eagerLoading()
{
if (!is_null($this->relations)) {
$this->model = $this->model->with($this->relations);
}
return $this;
}
示例4: getCollectionByColumn
/**
* 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);
}
示例5: with
/**
* 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;
}
示例6: index
/**
* 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]);
}
示例7: buildQuery
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']);
}
}
}
示例8: findByIdWithRelation
/**
* 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);
}
示例9: make
/**
* returns the query builder with eager loading, or the model itself
*
* @return Builder|Model
*/
protected function make()
{
return $this->model->with($this->with);
}
示例10: with
/**
* Load relations.
*
* @param array|string $relations
*
* @return $this
*/
public function with($relations)
{
$this->model = $this->model->with($relations);
return $this;
}
示例11: page
/**
* 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();
}
示例12: getModelWith
/**
* @return \Illuminate\Database\Eloquent\Model
*/
public function getModelWith()
{
return $this->model->with($this->with);
}
示例13: 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;
}
示例14: find
/**
* @param $id
* @param array|null $with
* @return mixed
*/
public function find($id, $with = [])
{
return $this->model->with($with)->findOrFail($id);
}
示例15: applyRelations
/**
* 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;
}