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