/** * Metodo para hacer la busqueda de un cliente */ public static function search() { $items = array(); $search = ''; if (Input::get('search')) { $search = Input::get('search'); $arrparam = explode(' ', $search); $items = Client::whereNested(function ($q) use($arrparam) { $p = $arrparam[0]; $q->whereNested(function ($q) use($p) { $q->where('name', 'LIKE', '%' . $p . '%'); $q->orwhere('telephone', 'LIKE', '%' . $p . '%'); $q->orwhere('address', 'LIKE', '%' . $p . '%'); }); $c = count($arrparam); if ($c > 1) { //para no repetir el primer elemento //foreach ($arrparam as $p) { for ($i = 1; $i < $c; $i++) { $p = $arrparam[$i]; $q->whereNested(function ($q) use($p) { $q->where('name', 'LIKE', '%' . $p . '%'); $q->orwhere('telephone', 'LIKE', '%' . $p . '%'); $q->orwhere('address', 'LIKE', '%' . $p . '%'); }, 'OR'); } } })->whereNull('deleted_at')->orderBy('name', 'ASC')->paginate(10); return View::make('client.view_client', compact('items', 'search')); } }