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