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