middleware(function ($request, $next) { $this->form = BusinessForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('eform.business.modules'), 'business', guard_url('business')); return $next($request); }); } /** * Display a list of business. * * @return Response */ public function index(BusinessResourceRequest $request) { $request = $request->all(); $page = BusinessActions::run('paginate', $request); $data = new BusinessesCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('business::business.names')) ->view('business::business.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display business. * * @param Request $request * @param Model $business * * @return Response */ public function show(BusinessResourceRequest $request, Business $model) { $form = $this->form; $modules = $this->modules; $data = new BusinessResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('business::business.name')) ->data(compact('data', 'form', 'modules')) ->view('business::business.show') ->output(); } /** * Show the form for creating a new business. * * @param Request $request * * @return Response */ public function create(BusinessResourceRequest $request, Business $model) { $form = $this->form; $modules = $this->modules; $data = new BusinessResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('business::business.name')) ->view('business::business.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new business. * * @param Request $request * * @return Response */ public function store(BusinessResourceRequest $request, Business $model) { try { $request = $request->all(); $model = BusinessAction::run('store', $model, $request); $data = new BusinessResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('business::business.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('business/business/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/business/business')) ->redirect(); } } /** * Show business for editing. * * @param Request $request * @param Model $business * * @return Response */ public function edit(BusinessResourceRequest $request, Business $model) { $form = $this->form; $modules = $this->modules; $data = new BusinessResource($model); // return view('business::business.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('business::business.name')) ->view('business::business.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the business. * * @param Request $request * @param Model $business * * @return Response */ public function update(BusinessResourceRequest $request, Business $model) { try { $request = $request->all(); $model = BusinessAction::run('update', $model, $request); $data = new BusinessResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('business::business.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('business/business/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('business/business/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the business. * * @param Model $business * * @return Response */ public function destroy(BusinessResourceRequest $request, Business $model) { try { $request = $request->all(); $model = BusinessAction::run('destroy', $model, $request); $data = new BusinessResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('business::business.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('business/business/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('business/business/' . $model->getRouteKey())) ->redirect(); } } }