本文整理汇总了PHP中Eloquent::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Eloquent::with方法的具体用法?PHP Eloquent::with怎么用?PHP Eloquent::with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Eloquent
的用法示例。
在下文中一共展示了Eloquent::with方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: with
/**
* @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: applyWith
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);
}
示例3: with
/**
* Begin querying a model with eager loading.
*
* @param array|string $relations
*/
public function with($relations)
{
$this->model->with($relations);
return $this;
}