Exemplo n.º 1
0
 /**
  * Display all clusters
  *
  * @param type, search, skip, take
  * @return Response
  */
 public function index($type = null)
 {
     if ($type == 'category') {
         $result = \App\Models\Category::orderby('path', 'asc')->with(['category']);
     } else {
         $result = \App\Models\Tag::orderby('path', 'asc')->with(['tag']);
     }
     if (Input::has('search')) {
         $search = Input::get('search');
         foreach ($search as $key => $value) {
             switch (strtolower($key)) {
                 case 'name':
                     $result = $result->name($value);
                     break;
                 default:
                     # code...
                     break;
             }
         }
     }
     $count = $result->count();
     if (Input::has('skip')) {
         $skip = Input::get('skip');
         $result = $result->skip($skip);
     }
     if (Input::has('take')) {
         $take = Input::get('take');
         $result = $result->take($take);
     }
     $result = $result->get()->toArray();
     return new JSend('success', (array) ['count' => $count, 'data' => $result]);
 }