repository = $car; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Testprovider\Testpackage\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(\Testprovider\Testpackage\Repositories\Presenter\CarPresenter::class) ->$function(); } $cars = $this->repository->paginate(); return $this->response->title(trans('testpackage::car.names')) ->view('testpackage::car.index', true) ->data(compact('cars')) ->output(); } /** * Display car. * * @param Request $request * @param Model $car * * @return Response */ public function show(CarRequest $request, Car $car) { if ($car->exists) { $view = 'testpackage::car.show'; } else { $view = 'testpackage::car.new'; } return $this->response->title(trans('app.view') . ' ' . trans('testpackage::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->title(trans('app.new') . ' ' . trans('testpackage::car.name')) ->view('testpackage::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('testpackage::car.name')])) ->code(204) ->status('success') ->url(guard_url('testpackage/car/' . $car->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/testpackage/car')) ->redirect(); } } /** * Show car for editing. * * @param Request $request * @param Model $car * * @return Response */ public function edit(CarRequest $request, Car $car) { return $this->response->title(trans('app.edit') . ' ' . trans('testpackage::car.name')) ->view('testpackage::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('testpackage::car.name')])) ->code(204) ->status('success') ->url(guard_url('testpackage/car/' . $car->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('testpackage/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('testpackage::car.name')])) ->code(202) ->status('success') ->url(guard_url('testpackage/car/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('testpackage/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('testpackage::car.name')])) ->status("success") ->code(202) ->url(guard_url('testpackage/car')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/testpackage/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('testpackage::car.name')])) ->status("success") ->code(202) ->url(guard_url('/testpackage/car')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/testpackage/car/')) ->redirect(); } } }