/** * Show the form for creating a new resource. * * @param Request $request * @param ApiService $apiService * @return \Illuminate\Http\Response */ public function create(Request $request, ApiService $apiService) { $response = $apiService->get(route('api.v1.0.spot.index'))->addHeader(['Authorization' => 'Bearer ' . $request->cookie('token')])->dispatch(); $spots = $response->getContent(); //massage the data into a nicer format for opgrouped select (TODO, maybe use a view composer?) $regions = []; foreach ($spots as $spot) { $regions[$spot->msw_spot->region][] = $spot; } $response = $apiService->get(route('api.v1.0.user.show'))->addHeader(['Authorization' => 'Bearer ' . $request->cookie('token')])->dispatch(); $profile = $response->getContent(); if (!count($spots)) { return redirect(route('spot.create', ['from_route' => 'surf.create'])); } return view('surfs.create')->with('regions', $regions)->with('profile', $profile); }
/** * Show the form for creating a new resource. * * @param Request $request * @param ApiService $apiService * @return \Illuminate\Http\Response */ public function create(Request $request, ApiService $apiService) { $mswCountriesList = $apiService->get(route('api.v1.0.msw-spot.index'), ['groupBy' => ['country']])->dispatch(); $mswCountriesList = $mswCountriesList->getContent(); //massage the data into a nicer format for opgrouped select (TODO, maybe use a view composer?) $mswCountries = []; foreach ($mswCountriesList as $mswCountry) { $mswCountries[$mswCountry->continent][] = $mswCountry; } return view('spots.create')->with('from_route', $request->query('from_route') ?: 'dashboard')->with('mswCountries', $mswCountries); }