コード例 #1
0
 /**
  * Metodo para hacer la busqueda
  */
 public static function search(Request $request)
 {
     $items = array();
     $search = '';
     if ($request->input('search')) {
         $search = $request->input('search');
         $arrparam = explode(' ', $search);
         $items = Activity::whereNested(function ($q) use($arrparam) {
             $p = $arrparam[0];
             $q->whereNested(function ($q) use($p) {
                 $q->where('id', 'LIKE', '%' . $p . '%');
                 $q->orwhere('name', 'LIKE', '%' . $p . '%');
                 $q->orwhere('reference', 'LIKE', '%' . $p . '%');
                 $q->orwhere('enable', 'LIKE', '%' . $p . '%');
             });
             $c = count($arrparam);
             if ($c > 1) {
                 for ($i = 1; $i < $c; $i++) {
                     $p = $arrparam[$i];
                     $q->whereNested(function ($q) use($p) {
                         $q->where('id', 'LIKE', '%' . $p . '%');
                         $q->orwhere('name', 'LIKE', '%' . $p . '%');
                         $q->orwhere('reference', 'LIKE', '%' . $p . '%');
                         $q->orwhere('enable', 'LIKE', '%' . $p . '%');
                     }, 'OR');
                 }
             }
         })->whereNull('deleted_at')->orderBy('name', 'ASC')->paginate(10);
         return View::make('admin.activity.view_activity', compact('items', 'search'));
     }
 }