/** * Responds to requests to GET /cars/edit/{$id} */ public function getEdit($id = null) { # Get this car and eager load its tags $car = \App\Car::with('tags')->find($id); if (is_null($car)) { \Session::flash('flash_message', 'Car not found.'); return redirect('\\cars'); } # Manufacturer dropdown $manufacturerModel = new \App\Manufacturer(); $manufacturers_for_dropdown = $manufacturerModel->getManufacturersForDropdown(); # Tag checkboxes $tagModel = new \App\Tag(); $tags_for_checkbox = $tagModel->getTagsForCheckboxes(); # Size dropdown $sizeModel = new \App\Size(); $sizes_for_dropdown = $sizeModel->getSizesForDropdown(); /* Create a simple array of just the tag names for tags associated with this car; will be used in the view to decide which tags should be checked off */ $tags_for_this_car = []; foreach ($car->tags as $tag) { $tags_for_this_car[] = $tag->name; } # Pass variables to the view return view('cars.edit')->with(['car' => $car, 'manufacturers_for_dropdown' => $manufacturers_for_dropdown, 'tags_for_checkbox' => $tags_for_checkbox, 'tags_for_this_car' => $tags_for_this_car, 'sizes_for_dropdown' => $sizes_for_dropdown]); }
public function homepage() { $user = Auth::user() ?: false; $cars = Car::with('inquiriesCount')->orderBy('domestic', 'asc')->orderBy('name')->get(); $cars1 = $cars->filter(function ($item) { return $item->name == "ВАЗ"; }); $cars2 = $cars->filter(function ($item) { return $item->name != "ВАЗ"; }); $cars = $cars1->merge($cars2); $carsList = $cars->lists('name', 'id')->toArray(); $lastInquiries = Inquiry::with('car', 'city')->orderBy('created_at', 'desc')->paginate(config('vars.inquiries_per_page')); $lastInquiries->setPath('inquiry/index'); Carbon::setLocale(config('app.locale')); $lastNews = News::orderBy('published_at', 'desc')->paginate(config('vars.news_per_page')); $lastNews->setPath('news/index'); $cities = City::lists('name', 'id')->all(); $blocks = Block::all()->keyBy('alias'); $faq = Faq::all(); return view('homepage', compact('user', 'cars', 'carsList', 'lastInquiries', 'lastNews', 'cities', 'blocks', 'faq')); }
/** * car rental history * @param $id * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function histories($id, Request $request) { //valdate month $this->validate($request, ['month' => 'required|date_format:m-Y']); //get rental history $histories = Car::with(['histories' => function ($query) use($request) { $monthyear = explode('-', $request->input('month')); $query->join('client', 'client.id', '=', 'rental.client-id')->whereRaw('(EXTRACT(MONTH FROM "date-from") = \'' . $monthyear[0] . '\' AND EXTRACT(YEAR FROM "date-from") = \'' . $monthyear[1] . '\') OR (EXTRACT(MONTH FROM "date-to") = \'' . $monthyear[0] . '\' AND EXTRACT(YEAR FROM "date-to") = \'' . $monthyear[1] . '\')')->select('car-id', 'client.name AS rent-by', 'date-from', 'date-to'); }])->find($id); if ($histories == null) { $histories = ['error' => 'Car data not found']; } return response()->json($histories); }
public function api_all() { return Car::with('investor')->get(); }