repository = $car; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Autos\Car\Repositories\Criteria\CarResourceCriteria::class); } /** * Display a list of car. * * @return Response */ public function index(CarRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Autos\Car\Repositories\Presenter\CarPresenter::class) ->$function(); } $cars = $this->repository->paginate(); return $this->response->setMetaTitle(trans('car::car.names')) ->view('car::car.index', true) ->data(compact('cars', 'view')) ->output(); } /** * Display car. * * @param Request $request * @param Model $car * * @return Response */ public function show(CarRequest $request, Car $car) { if ($car->exists) { $view = 'car::car.show'; } else { $view = 'car::car.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('car::car.name')) ->data(compact('car')) ->view($view, true) ->output(); } /** * Show the form for creating a new car. * * @param Request $request * * @return Response */ public function create(CarRequest $request) { $car = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('car::car.name')) ->view('car::car.create', true) ->data(compact('car')) ->output(); } /** * Create new car. * * @param Request $request * * @return Response */ public function store(CarRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $car = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('car::car.name')])) ->code(204) ->status('success') ->url(guard_url('car/car/' . $car->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/car/car')) ->redirect(); } } /** * Show car for editing. * * @param Request $request * @param Model $car * * @return Response */ public function edit(CarRequest $request, Car $car) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('car::car.name')) ->view('car::car.edit', true) ->data(compact('car')) ->output(); } /** * Update the car. * * @param Request $request * @param Model $car * * @return Response */ public function update(CarRequest $request, Car $car) { try { $attributes = $request->all(); $car->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('car::car.name')])) ->code(204) ->status('success') ->url(guard_url('car/car/' . $car->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('car/car/' . $car->getRouteKey())) ->redirect(); } } /** * Remove the car. * * @param Model $car * * @return Response */ public function destroy(CarRequest $request, Car $car) { try { $car->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('car::car.name')])) ->code(202) ->status('success') ->url(guard_url('car/car/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('car/car/' . $car->getRouteKey())) ->redirect(); } } /** * Remove multiple car. * * @param Model $car * * @return Response */ public function delete(CarRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('car::car.name')])) ->status("success") ->code(202) ->url(guard_url('car/car')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/car/car')) ->redirect(); } } /** * Restore deleted cars. * * @param Model $car * * @return Response */ public function restore(CarRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('car::car.name')])) ->status("success") ->code(202) ->url(guard_url('/car/car')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/car/car/')) ->redirect(); } } }