本文整理匯總了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;
}