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