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