form = AccountForm::setAttributes()->toArray(); $this->modules = $this->modules(config('inventory.account.modules'), 'account', guard_url('account')); $this->repository = $account; } /** * Display a list of account. * * @return Response */ public function index(AccountRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $data = $this->repository ->pushFilter(RequestFilter::class) ->pushFilter(AccountResourceFilter::class) ->setPresenter(AccountListPresenter::class) ->simplePaginate($pageLimit) // ->withQueryString() ->toArray(); extract($data); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('account::account.names')) ->view('account::account.index') ->data(compact('data', 'meta', 'links', 'modules', 'form')) ->output(); } /** * Display account. * * @param Request $request * @param Model $account * * @return Response */ public function show(AccountRequest $request, AccountRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('account::account.name')) ->data(compact('data', 'form', 'modules', 'form')) ->view('account::account.show') ->output(); } /** * Show the form for creating a new account. * * @param Request $request *x * @return Response */ public function create(AccountRequest $request, AccountRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('account::account.name')) ->view('account::account.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new account. * * @param Request $request * * @return Response */ public function store(AccountRequest $request, AccountRepositoryInterface $repository) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $repository->create($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.created', ['Module' => trans('account::account.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('account/account/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/account/account')) ->redirect(); } } /** * Show account for editing. * * @param Request $request * @param Model $account * * @return Response */ public function edit(AccountRequest $request, AccountRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('account::account.name')) ->view('account::account.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the account. * * @param Request $request * @param Model $account * * @return Response */ public function update(AccountRequest $request, AccountRepositoryInterface $repository) { try { $attributes = $request->all(); $repository->update($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.updated', ['Module' => trans('account::account.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('account/account/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('account/account/' . $repository->getRouteKey())) ->redirect(); } } /** * Remove the account. * * @param Model $account * * @return Response */ public function destroy(AccountRequest $request, AccountRepositoryInterface $repository) { try { $repository->delete(); $data = $repository->toArray(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('account::account.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('account/account/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('account/account/' . $repository->getRouteKey())) ->redirect(); } } }