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