/** * @SWG\Get( * path="/mastoria", * description="Returns all the mastoria", * operationId="getMastoria", * tags={"mastoria"}, * produces={"application/json"}, * @SWG\Parameter( * description="Access token", * in="header", * name="Authorization", * required=true, * type="string" * ), * @SWG\Response( * response=200, * description="All mastoria response", * @SWG\Schema( * type="array", * @SWG\Items(ref="#/definitions/mastori") * ), * ), * @SWG\Response( * response="400", * description="token_not_provided", * @SWG\Schema( * ref="#/definitions/errorModel" * ) * ) * ) */ public function index(Request $request) { $filterColumns = ['active' => 'active', 'last_name' => 'last_name', 'offers' => 'offers', 'avg_rating' => 'avg_rating', 'avg_response_time' => 'avg_response_time', 'profession' => 'mastoria_professions.profession_id', 'area' => 'mastoria_areas.area_id', 'created_at' => 'created_at']; $mastoria = Mastori::leftJoin('mastoria_professions', 'mastoria.id', '=', 'mastoria_professions.mastori_id'); if ($request->input('area') !== null || $request->input('userlocation') !== null) { $mastoria->leftJoin('mastoria_areas', 'mastoria.id', '=', 'mastoria_areas.mastori_id'); } //when end user's lat,lng is provided, get mastoria that serve the location /*DOES NOT WORK WHEN AREA IS PROVIDED*/ if ($request->input('userlocation')) { $mastoria->UserLocation($request->input('userlocation')); } $mastoria->filterColumns($filterColumns)->groupBy('mastoria.id')->select('mastoria.*'); if ($request->input('q')) { $mastoria = $mastoria->q($request->input('q')); } if ($request->input('only_offers')) { $mastoria = $mastoria->offers(); } if ($request->input('near')) { $mastoria = $mastoria->near($request->input('near'), $request->input('radius')); } if (Auth::guest() || Auth::user()->userable_type !== 'App\\Admin') { $mastoria = $mastoria->active(); } return $mastoria->with('user')->with('professions')->with('areas')->paginate($request->input('per_page')); }