Example #1
0
 /**
  * Has role scope.
  * 
  * @param  Builder $query 
  * @param  string  $type  
  * @return Builder        
  */
 public function scopeHasRole($query, $type)
 {
     return $query->whereHas('roles', function ($query) use($type) {
         $query->where('slug', $type);
     });
 }
Example #2
0
 /**
  * Process STRING type of search
  * @param Builder $query
  * @param string $key
  * @param array $values
  */
 protected function setStringSearchQuery($query, $key, array $values)
 {
     $value = $values['values'][0];
     switch ($values['operator']) {
         case '~':
             if (isset(static::$searchParams[$key]['relation'])) {
                 $relationKey = static::$searchParams[$key]['relation'][1];
                 $query->whereHas(static::$searchParams[$key]['relation'][0], function ($q) use($relationKey, $value) {
                     $q->where($relationKey, 'LIKE', "%{$value}%");
                 });
             } else {
                 $query->where($key, 'LIKE', "%{$value}%");
             }
             break;
         case '!~':
             if (isset(static::$searchParams[$key]['relation'])) {
                 $relationKey = static::$searchParams[$key]['relation'][1];
                 $query->whereHas(static::$searchParams[$key]['relation'][0], function ($q) use($relationKey, $value) {
                     $q->where($relationKey, 'NOT LIKE', "%{$value}%");
                 });
             } else {
                 $query->where($key, 'NOT LIKE', "%{$value}%");
             }
             break;
     }
 }
Example #3
0
 /**
  * @param array   $queries
  * @param Builder $model
  *
  * @return Builder;
  */
 public function whereHasPostMeta($queries, $model)
 {
     $queries = $this->sanitizeQuery($queries);
     return $model->whereHas('postMeta', function ($q) use($queries) {
         $this->metaQueryClause($queries, $q);
     });
 }