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