repository = $accounts; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Bixo\Contact\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\Contact\Repositories\Presenter\AccountsPresenter::class) ->$function(); } $accounts = $this->repository->paginate(); return $this->response->setMetaTitle(trans('contact::accounts.names')) ->view('contact::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 = 'contact::accounts.show'; } else { $view = 'contact::accounts.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('contact::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('contact::accounts.name')) ->view('contact::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('contact::accounts.name')])) ->code(204) ->status('success') ->url(guard_url('contact/accounts/' . $accounts->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/contact/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('contact::accounts.name')) ->view('contact::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('contact::accounts.name')])) ->code(204) ->status('success') ->url(guard_url('contact/accounts/' . $accounts->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('contact/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('contact::accounts.name')])) ->code(202) ->status('success') ->url(guard_url('contact/accounts/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('contact/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('contact::accounts.name')])) ->status("success") ->code(202) ->url(guard_url('contact/accounts')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/contact/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('contact::accounts.name')])) ->status("success") ->code(202) ->url(guard_url('/contact/accounts')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/contact/accounts/')) ->redirect(); } } }