form = DealForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('litecms.deal.modules'), 'deal', guard_url('deal')); } /** * Display a list of deal. * * @return Response */ public function index(DealResourceRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $page = Deal::pushScope(new RequestScope()) ->pushScope(new DealResourceScope()) ->paginate($pageLimit); $data = new DealsCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('deal::deal.names')) ->view('deal::deal.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display deal. * * @param Request $request * @param Model $deal * * @return Response */ public function show(DealResourceRequest $request, Deal $model) { $form = $this->form; $modules = $this->modules; $data = new DealResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('deal::deal.name')) ->data(compact('data', 'form', 'modules')) ->view('deal::deal.show') ->output(); } /** * Show the form for creating a new deal. * * @param Request $request * * @return Response */ public function create(DealResourceRequest $request, Deal $model) { $form = $this->form; $modules = $this->modules; $data = new DealResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('deal::deal.name')) ->view('deal::deal.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new deal. * * @param Request $request * * @return Response */ public function store(DealResourceRequest $request, Deal $model) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $model = $model->create($attributes); $data = new DealResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('deal::deal.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('deal/deal/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/deal/deal')) ->redirect(); } } /** * Show deal for editing. * * @param Request $request * @param Model $deal * * @return Response */ public function edit(DealResourceRequest $request, Deal $model) { $form = $this->form; $modules = $this->modules; $data = new DealResource($model); // return view('deal::deal.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('deal::deal.name')) ->view('deal::deal.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the deal. * * @param Request $request * @param Model $deal * * @return Response */ public function update(DealResourceRequest $request, Deal $model) { try { $attributes = $request->all(); $model->update($attributes); $data = new DealResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('deal::deal.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('deal/deal/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('deal/deal/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the deal. * * @param Model $deal * * @return Response */ public function destroy(DealResourceRequest $request, Deal $model) { try { $model->delete(); $data = new DealResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('deal::deal.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('deal/deal/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('deal/deal/' . $model->getRouteKey())) ->redirect(); } } }