repository = $emails; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litecms\Email\Repositories\Criteria\EmailsResourceCriteria::class); } /** * Display a list of emails. * * @return Response */ public function index(EmailsRequest $request) { return $this->repository ->setPresenter(\Litecms\Email\Repositories\Presenter\EmailsPresenter::class) ->paginate(); } /** * Display emails. * * @param Request $request * @param Model $emails * * @return Response */ public function show(EmailsRequest $request, Emails $emails) { return $emails->setPresenter(\Litecms\Email\Repositories\Presenter\EmailsListPresenter::class); ; } /** * Create new emails. * * @param Request $request * * @return Response */ public function store(EmailsRequest $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('email::emails.name')]); $code = 204; $status = 'success'; $url = guard_url('email/emails/' . $emails->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('email/emails'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the emails. * * @param Request $request * @param Model $emails * * @return Response */ public function update(EmailsRequest $request, Emails $emails) { try { $data = $request->all(); $emails->update($data); $message = trans('messages.success.updated', ['Module' => trans('email::emails.name')]); $code = 204; $status = 'success'; $url = guard_url('email/emails/' . $emails->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('email/emails/' . $emails->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the emails. * * @param Model $emails * * @return Response */ public function destroy(EmailsRequest $request, Emails $emails) { try { $emails->delete(); $message = trans('messages.success.deleted', ['Module' => trans('email::emails.name')]); $code = 202; $status = 'success'; $url = guard_url('email/emails/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('email/emails/' . $emails->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); } }