form = CarmodelForm::setAttributes()->toArray(); $this->modules = $this->modules(config('laraautos.car.modules'), 'car', guard_url('car')); $this->repository = $carmodel; } /** * Display a list of carmodel. * * @return Response */ public function index(CarmodelRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $data = $this->repository ->pushFilter(RequestFilter::class) ->pushFilter(CarmodelResourceFilter::class) ->setPresenter(CarmodelListPresenter::class) ->simplePaginate($pageLimit) // ->withQueryString() ->toArray(); extract($data); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('car::carmodel.names')) ->view('car::carmodel.index') ->data(compact('data', 'meta', 'links', 'modules', 'form')) ->output(); } /** * Display carmodel. * * @param Request $request * @param Model $carmodel * * @return Response */ public function show(CarmodelRequest $request, CarmodelRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('car::carmodel.name')) ->data(compact('data', 'form', 'modules', 'form')) ->view('car::carmodel.show') ->output(); } /** * Show the form for creating a new carmodel. * * @param Request $request *x * @return Response */ public function create(CarmodelRequest $request, CarmodelRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('car::carmodel.name')) ->view('car::carmodel.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new carmodel. * * @param Request $request * * @return Response */ public function store(CarmodelRequest $request, CarmodelRepositoryInterface $repository) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $repository->create($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.created', ['Module' => trans('car::carmodel.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('car/carmodel/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/car/carmodel')) ->redirect(); } } /** * Show carmodel for editing. * * @param Request $request * @param Model $carmodel * * @return Response */ public function edit(CarmodelRequest $request, CarmodelRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('car::carmodel.name')) ->view('car::carmodel.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the carmodel. * * @param Request $request * @param Model $carmodel * * @return Response */ public function update(CarmodelRequest $request, CarmodelRepositoryInterface $repository) { try { $attributes = $request->all(); $repository->update($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.updated', ['Module' => trans('car::carmodel.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('car/carmodel/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('car/carmodel/' . $repository->getRouteKey())) ->redirect(); } } /** * Remove the carmodel. * * @param Model $carmodel * * @return Response */ public function destroy(CarmodelRequest $request, CarmodelRepositoryInterface $repository) { try { $repository->delete(); $data = $repository->toArray(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('car::carmodel.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('car/carmodel/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('car/carmodel/' . $repository->getRouteKey())) ->redirect(); } } }