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) { return $this->repository ->setPresenter(\Bixo\Contact\Repositories\Presenter\AccountsPresenter::class) ->paginate(); } /** * Display accounts. * * @param Request $request * @param Model $accounts * * @return Response */ public function show(AccountsRequest $request, Accounts $accounts) { return $accounts->setPresenter(\Bixo\Contact\Repositories\Presenter\AccountsListPresenter::class); ; } /** * Create new accounts. * * @param Request $request * * @return Response */ public function store(AccountsRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('contact::accounts.name')]); $code = 204; $status = 'success'; $url = guard_url('contact/accounts/' . $accounts->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('contact/accounts'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the accounts. * * @param Request $request * @param Model $accounts * * @return Response */ public function update(AccountsRequest $request, Accounts $accounts) { try { $data = $request->all(); $accounts->update($data); $message = trans('messages.success.updated', ['Module' => trans('contact::accounts.name')]); $code = 204; $status = 'success'; $url = guard_url('contact/accounts/' . $accounts->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('contact/accounts/' . $accounts->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the accounts. * * @param Model $accounts * * @return Response */ public function destroy(AccountsRequest $request, Accounts $accounts) { try { $accounts->delete(); $message = trans('messages.success.deleted', ['Module' => trans('contact::accounts.name')]); $code = 202; $status = 'success'; $url = guard_url('contact/accounts/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('contact/accounts/' . $accounts->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }