Ejemplo n.º 1
0
 /**
  * Query builder scope to search on text
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $search      Search term
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeTextSearch($query, $search)
 {
     return $query->where('name', 'LIKE', "%{$search}%")->orWhere('modelno', 'LIKE', "%{$search}%")->orWhere(function ($query) use($search) {
         $query->whereHas('depreciation', function ($query) use($search) {
             $query->where('name', 'LIKE', '%' . $search . '%');
         });
     })->orWhere(function ($query) use($search) {
         $query->whereHas('category', function ($query) use($search) {
             $query->where('name', 'LIKE', '%' . $search . '%');
         });
     })->orWhere(function ($query) use($search) {
         $query->whereHas('manufacturer', function ($query) use($search) {
             $query->where('name', 'LIKE', '%' . $search . '%');
         });
     });
 }
Ejemplo n.º 2
0
 /**
  * Query builder scope to search on text
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $search    	 Search term
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeTextsearch($query, $search)
 {
     return $query->where('name', 'LIKE', "%{$search}%")->orWhere('address', 'LIKE', "%{$search}%")->orWhere('city', 'LIKE', "%{$search}%")->orWhere('state', 'LIKE', "%{$search}%")->orWhere('zip', 'LIKE', "%{$search}%")->orWhere(function ($query) use($search) {
         $query->whereHas('parent', function ($query) use($search) {
             $query->where(function ($query) use($search) {
                 $query->where('name', 'LIKE', '%' . $search . '%');
             });
         })->orWhere(function ($query) use($search) {
             $query->whereRaw("parent_id IN (select id from locations where name LIKE '%" . $search . "%') ");
         });
     });
 }
Ejemplo n.º 3
0
 /**
  * Query builder scope to search on text
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $search      Search term
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeTextSearch($query, $search)
 {
     $search = explode('+', $search);
     return $query->where(function ($query) use($search) {
         foreach ($search as $search) {
             $query->whereHas('category', function ($query) use($search) {
                 $query->where('categories.name', 'LIKE', '%' . $search . '%');
             })->orWhere(function ($query) use($search) {
                 $query->whereHas('company', function ($query) use($search) {
                     $query->where('companies.name', 'LIKE', '%' . $search . '%');
                 });
             })->orWhere(function ($query) use($search) {
                 $query->whereHas('assetlog', function ($query) use($search) {
                     $query->where('action_type', '=', 'checkout')->where('created_at', 'LIKE', '%' . $search . '%');
                 });
             })->orWhere(function ($query) use($search) {
                 $query->whereHas('location', function ($query) use($search) {
                     $query->where('locations.name', 'LIKE', '%' . $search . '%');
                 });
             })->orWhere('accessories.name', 'LIKE', '%' . $search . '%')->orWhere('accessories.order_number', 'LIKE', '%' . $search . '%')->orWhere('accessories.purchase_cost', 'LIKE', '%' . $search . '%')->orWhere('accessories.purchase_date', 'LIKE', '%' . $search . '%');
         }
     });
 }
Ejemplo n.º 4
0
 /**
  * Query builder scope to search on text
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $search      Search term
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeTextSearch($query, $search)
 {
     $search = explode(' ', $search);
     return $query->where(function ($query) use($search) {
         foreach ($search as $search) {
             $query->whereHas('category', function ($query) use($search) {
                 $query->where('categories.name', 'LIKE', '%' . $search . '%');
             })->orWhere(function ($query) use($search) {
                 $query->whereHas('company', function ($query) use($search) {
                     $query->where('companies.name', 'LIKE', '%' . $search . '%');
                 });
             })->orWhere(function ($query) use($search) {
                 $query->whereHas('location', function ($query) use($search) {
                     $query->where('locations.name', 'LIKE', '%' . $search . '%');
                 });
             })->orWhere('consumables.name', 'LIKE', '%' . $search . '%')->orWhere('consumables.order_number', 'LIKE', '%' . $search . '%')->orWhere('consumables.purchase_cost', 'LIKE', '%' . $search . '%')->orWhere('consumables.purchase_date', 'LIKE', '%' . $search . '%');
         }
     });
 }
Ejemplo n.º 5
0
 /**
  * Query builder scope to search on text for complex Bootstrap Tables API
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $search      Search term
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeTextSearch($query, $search)
 {
     $search = explode(' OR ', $search);
     return $query->where(function ($query) use($search) {
         foreach ($search as $search) {
             $query->whereHas('model', function ($query) use($search) {
                 $query->whereHas('category', function ($query) use($search) {
                     $query->where(function ($query) use($search) {
                         $query->where('categories.name', 'LIKE', '%' . $search . '%')->orWhere('models.name', 'LIKE', '%' . $search . '%')->orWhere('models.modelno', 'LIKE', '%' . $search . '%');
                     });
                 });
             })->orWhereHas('model', function ($query) use($search) {
                 $query->whereHas('manufacturer', function ($query) use($search) {
                     $query->where(function ($query) use($search) {
                         $query->where('manufacturers.name', 'LIKE', '%' . $search . '%');
                     });
                 });
             })->orWhere(function ($query) use($search) {
                 $query->whereHas('assetstatus', function ($query) use($search) {
                     $query->where('status_labels.name', 'LIKE', '%' . $search . '%');
                 });
             })->orWhere(function ($query) use($search) {
                 $query->whereHas('company', function ($query) use($search) {
                     $query->where('companies.name', 'LIKE', '%' . $search . '%');
                 });
             })->orWhere(function ($query) use($search) {
                 $query->whereHas('defaultLoc', function ($query) use($search) {
                     $query->where('locations.name', 'LIKE', '%' . $search . '%');
                 });
             })->orWhere(function ($query) use($search) {
                 $query->whereHas('assigneduser', function ($query) use($search) {
                     $query->where(function ($query) use($search) {
                         $query->where('users.first_name', 'LIKE', '%' . $search . '%')->orWhere('users.last_name', 'LIKE', '%' . $search . '%')->orWhere(function ($query) use($search) {
                             $query->whereHas('userloc', function ($query) use($search) {
                                 $query->where('locations.name', 'LIKE', '%' . $search . '%');
                             });
                         });
                     });
                 });
             })->orWhere('assets.name', 'LIKE', '%' . $search . '%')->orWhere('assets.asset_tag', 'LIKE', '%' . $search . '%')->orWhere('assets.serial', 'LIKE', '%' . $search . '%')->orWhere('assets.order_number', 'LIKE', '%' . $search . '%')->orWhere('assets.notes', 'LIKE', '%' . $search . '%');
         }
         foreach (CustomField::all() as $field) {
             $query->orWhere($field->db_column_name(), 'LIKE', "%{$search}%");
         }
     });
 }
Ejemplo n.º 6
0
 /**
  * Query builder scope to search on text
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $search      Search term
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeTextsearch($query, $search)
 {
     return $query->where(function ($query) use($search) {
         $query->where('users.first_name', 'LIKE', "%{$search}%")->orWhere('users.last_name', 'LIKE', "%{$search}%")->orWhere('users.email', 'LIKE', "%{$search}%")->orWhere('users.username', 'LIKE', "%{$search}%")->orWhere('users.notes', 'LIKE', "%{$search}%")->orWhere('users.employee_num', 'LIKE', "%{$search}%")->orWhere(function ($query) use($search) {
             $query->whereHas('userloc', function ($query) use($search) {
                 $query->where('locations.name', 'LIKE', '%' . $search . '%');
             });
         })->orWhere(function ($query) use($search) {
             $query->whereRaw("users.manager_id IN (select id from users where first_name LIKE '%" . $search . "%' OR last_name LIKE '%" . $search . "%') ");
         });
     });
 }
Ejemplo n.º 7
0
 /**
  * Query builder scope for Archived assets
  *
  * @param  Illuminate\Database\Query\Builder $query Query builder instance
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeArchived($query)
 {
     return $query->whereHas('assetstatus', function ($query) {
         $query->where('deployable', '=', 0)->where('pending', '=', 0)->where('archived', '=', 1);
     });
 }
Ejemplo n.º 8
0
 /**
  * Query builder scope to search on text for complex Bootstrap Tables API
  *
  * @param  Illuminate\Database\Query\Builder  $query  Query builder instance
  * @param  text                              $search    	 Search term
  *
  * @return Illuminate\Database\Query\Builder          Modified query builder
  */
 public function scopeTextSearch($query, $search)
 {
     $search = explode('+', $search);
     return $query->where(function ($query) use($search) {
         foreach ($search as $search) {
             $query->whereHas('model', function ($query) use($search) {
                 $query->whereHas('category', function ($query) use($search) {
                     $query->where(function ($query) use($search) {
                         $query->where('categories.name', 'LIKE', '%' . $search . '%')->orWhere('models.name', 'LIKE', '%' . $search . '%');
                     });
                 });
             })->orWhere(function ($query) use($search) {
                 $query->whereHas('assetstatus', function ($query) use($search) {
                     $query->where('name', 'LIKE', '%' . $search . '%');
                 });
             })->orWhere(function ($query) use($search) {
                 $query->whereHas('defaultLoc', function ($query) use($search) {
                     $query->where('name', 'LIKE', '%' . $search . '%');
                 });
             })->orWhere(function ($query) use($search) {
                 $query->whereHas('assigneduser', function ($query) use($search) {
                     $query->where(function ($query) use($search) {
                         $query->where('users.first_name', 'LIKE', '%' . $search . '%')->orWhere('users.last_name', 'LIKE', '%' . $search . '%')->orWhere(function ($query) use($search) {
                             $query->whereHas('userloc', function ($query) use($search) {
                                 $query->where('locations.name', 'LIKE', '%' . $search . '%');
                             });
                         });
                     });
                 });
             })->orWhere(function ($query) use($search) {
                 $query->whereHas('assetlog', function ($query) use($search) {
                     $query->where('action_type', '=', 'checkout')->where('created_at', 'LIKE', '%' . $search . '%');
                 });
             })->orWhere('name', 'LIKE', '%' . $search . '%')->orWhere('asset_tag', 'LIKE', '%' . $search . '%')->orWhere('serial', 'LIKE', '%' . $search . '%')->orWhere('order_number', 'LIKE', '%' . $search . '%')->orWhere('notes', 'LIKE', '%' . $search . '');
         }
     });
 }
Ejemplo n.º 9
0
 /**
  * Query scope "isAllowed".
  *
  * @param   Illuminate\Database\Query\Builder   $query
  * @return  Illuminate\Database\Query\Builder
  */
 public function scopeIsAllowed($query)
 {
     return $query->whereHas('user', function ($q) {
         return $q->whereId(auth()->id());
     });
 }
Ejemplo n.º 10
0
 /**
  * Filter the joined table of the query by the value passed in $filters
  *
  * @author Luca Brognara
  * @date December 2015
  *
  * @param Illuminate\Database\Query\Builder $query
  * @param string 							 $model
  * @param array 							 $filters
  * @param string 							 $filters
  *
  * @return array
  */
 public function scopeFilterBy($query, $model, $filters, $table)
 {
     if (count($filters) == 0) {
         return $query;
     }
     return $query->whereHas($model, function ($query) use($filters, $table) {
         try {
             $this->filter($query, $filters, $this->get_table_columns($table));
         } catch (\Exception $e) {
             throw new \Exception($e->getMessage(), $e->getCode());
         }
     });
 }