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