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('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.º 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(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 . "%') ");
         });
     });
 }