repository = $contact; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litepie\Medium\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(\Litepie\Medium\Repositories\Presenter\ContactPresenter::class) ->$function(); } $contacts = $this->repository->paginate(); return $this->response->setMetaTitle(trans('medium::contact.names')) ->view('medium::contact.index', true) ->data(compact('contacts', 'view')) ->output(); } /** * Display contact. * * @param Request $request * @param Model $contact * * @return Response */ public function show(ContactRequest $request, Contact $contact) { if ($contact->exists) { $view = 'medium::contact.show'; } else { $view = 'medium::contact.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('medium::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->setMetaTitle(trans('app.new') . ' ' . trans('medium::contact.name')) ->view('medium::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('medium::contact.name')])) ->code(204) ->status('success') ->url(guard_url('medium/contact/' . $contact->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/medium/contact')) ->redirect(); } } /** * Show contact for editing. * * @param Request $request * @param Model $contact * * @return Response */ public function edit(ContactRequest $request, Contact $contact) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('medium::contact.name')) ->view('medium::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('medium::contact.name')])) ->code(204) ->status('success') ->url(guard_url('medium/contact/' . $contact->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('medium/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('medium::contact.name')])) ->code(202) ->status('success') ->url(guard_url('medium/contact/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('medium/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('medium::contact.name')])) ->status("success") ->code(202) ->url(guard_url('medium/contact')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/medium/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('medium::contact.name')])) ->status("success") ->code(202) ->url(guard_url('/medium/contact')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/medium/contact/')) ->redirect(); } } }