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