本文整理汇总了PHP中Eloquent::whereHas方法的典型用法代码示例。如果您正苦于以下问题:PHP Eloquent::whereHas方法的具体用法?PHP Eloquent::whereHas怎么用?PHP Eloquent::whereHas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Eloquent
的用法示例。
在下文中一共展示了Eloquent::whereHas方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applyWhereHas
function applyWhereHas()
{
ksort($this->query_where_has);
foreach ($this->query_where_has as $path => $callbacks) {
$this->model->with($path);
$this->model->whereHas($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], (array) $params));
}
});
}
}
示例2: getAll
/**
* Grab all contacts for the supplied model
* @uses CrudHelper::index Grabs all items for a given model
* @param Eloquent $model The eloquent model to search contacts
* @return Collection The collection of all contacts
*/
public function getAll($model, $filter = null)
{
switch (true) {
case isset($filter):
$contacts = $model->whereHas('category', function ($query) use($filter) {
$query->where('category', '=', $filter);
})->paginate(15);
break;
default:
// Grab all contacts using the Sapioweb CrudHelper
$contacts = CrudHelper::index($model)->paginate(15);
break;
}
return $contacts;
}