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