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