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