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