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