form = MessageForm::setAttributes()->toArray(); $this->modules = $this->modules(config('litepie.message.modules'), 'message', guard_url('message')); $this->repository = $message; } /** * Display a list of message. * * @return Response */ public function index(MessageRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $data = $this->repository ->pushFilter(RequestFilter::class) ->pushFilter(MessageResourceFilter::class) ->setPresenter(MessageListPresenter::class) ->simplePaginate($pageLimit) // ->withQueryString() ->toArray(); extract($data); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('message::message.names')) ->view('message::message.index') ->data(compact('data', 'meta', 'links', 'modules', 'form')) ->output(); } /** * Display message. * * @param Request $request * @param Model $message * * @return Response */ public function show(MessageRequest $request, MessageRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('message::message.name')) ->data(compact('data', 'form', 'modules', 'form')) ->view('message::message.show') ->output(); } /** * Show the form for creating a new message. * * @param Request $request *x * @return Response */ public function create(MessageRequest $request, MessageRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('message::message.name')) ->view('message::message.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new message. * * @param Request $request * * @return Response */ public function store(MessageRequest $request, MessageRepositoryInterface $repository) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $repository->create($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.created', ['Module' => trans('message::message.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('message/message/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/message/message')) ->redirect(); } } /** * Show message for editing. * * @param Request $request * @param Model $message * * @return Response */ public function edit(MessageRequest $request, MessageRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('message::message.name')) ->view('message::message.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the message. * * @param Request $request * @param Model $message * * @return Response */ public function update(MessageRequest $request, MessageRepositoryInterface $repository) { try { $attributes = $request->all(); $repository->update($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.updated', ['Module' => trans('message::message.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('message/message/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('message/message/' . $repository->getRouteKey())) ->redirect(); } } /** * Remove the message. * * @param Model $message * * @return Response */ public function destroy(MessageRequest $request, MessageRepositoryInterface $repository) { try { $repository->delete(); $data = $repository->toArray(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('message::message.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('message/message/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('message/message/' . $repository->getRouteKey())) ->redirect(); } } }