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