orWhereHas() public method

Add a relationship count / exists condition to the query with where clauses and an "or".
public orWhereHas ( string $relation, Closure $callback, string $operator = '>=', integer $count = 1 ) : Builder | static
$relation string
$callback Closure
$operator string
$count integer
return Builder | static
Esempio n. 1
0
 /**
  * Constrain the given users query by the provided permission.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  string  $permission
  * @param  \Illuminate\Database\Eloquent\Model|string|null  $model
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function constrainUsers($query, $permission, $model = null)
 {
     return $query->where(function ($query) use($permission, $model) {
         $query->whereHas('permissions', $this->getPermissionConstraint($permission, $model));
         $query->orWhereHas('roles', $this->getRoleConstraint($permission, $model));
     });
 }
Esempio n. 2
0
 /**
  * Constrain the given users query by the provided ability.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  string  $ability
  * @param  \Illuminate\Database\Eloquent\Model|string|null  $model
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function constrainUsers($query, $ability, $model = null)
 {
     return $query->where(function ($query) use($ability, $model) {
         $query->whereHas('abilities', $this->getAbilityConstraint($ability, $model));
         $query->orWhereHas('roles', $this->getRoleConstraint($ability, $model));
     });
 }
Esempio n. 3
0
 /**
  * Add a relationship count condition to the query with where clauses and an "or".
  *
  * @param string $relation
  * @param \Closure $callback
  * @param string $operator
  * @param int $count
  * @return \Illuminate\Database\Eloquent\Builder|static 
  * @static 
  */
 public static function orWhereHas($relation, $callback, $operator = '>=', $count = 1)
 {
     return \Illuminate\Database\Eloquent\Builder::orWhereHas($relation, $callback, $operator, $count);
 }
Esempio n. 4
0
 /**
  * Build wildcard query filters.
  *
  * @param  \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder  $query
  * @param  array  $fields
  * @param  array  $keyword
  * @param  string  $group
  *
  * @return void
  */
 protected function buildWildcardQueryFilters($query, array $fields, array $keyword = [])
 {
     foreach ($fields as $field) {
         if (Str::contains($field, '.') && $query instanceof Builder) {
             list($relation, $field) = explode('.', $field, 2);
             $query->orWhereHas($relation, function ($query) use($field, $keyword) {
                 $this->buildWildcardQueryFilterWithKeyword($query, $field, $keyword, 'where');
             });
         } else {
             $this->buildWildcardQueryFilterWithKeyword($query, $field, $keyword, 'orWhere');
         }
     }
 }