whereHas() public static method

Add a relationship count / exists condition to the query with where clauses.
public static whereHas ( string $relation, Closure $callback, string $operator = '>=', integer $count = 1 ) : Builder | static
$relation string
$callback Closure
$operator string
$count integer
return Illuminate\Database\Eloquent\Builder | static
コード例 #1
1
ファイル: FormFilter.php プロジェクト: larakit/lk
 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
0
 /**
  * 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;
 }