function index(Request $request) { ///////////////// // Load Filter // ///////////////// $filters = $request->only('name', 'slug', 'skip', 'take', 'with_count'); /////////// // Query // /////////// $q = Model::name($filters['name'])->slug($filters['slug']); if ($filters['with_count']) { $count = $q->count(); } $data = $q->select('name', 'slug', 'location')->skip($filters['skip'])->take($filters['take'])->orderBy('slug')->get(); ////////////// // Response // ////////////// return response()->json(JSend::success(['count' => $count, 'data' => $data->toArray()])->asArray()); }