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