middleware('web'); $this->middleware('auth:web'); $this->setupTheme(config('theme.themes.user.theme'), config('theme.themes.user.layout')); $this->repository = $student; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(StudentUserWebRequest $request) { $this->repository->pushCriteria(new \Assetdocs\Student\Repositories\Criteria\StudentUserCriteria()); $students = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('student::student.names').' :: '); return $this->theme->of('student::user.student.index', compact('students'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Student $student * * @return Response */ public function show(StudentUserWebRequest $request, Student $student) { Form::populate($student); return $this->theme->of('student::user.student.show', compact('student'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(StudentUserWebRequest $request) { $student = $this->repository->newInstance([]); Form::populate($student); return $this->theme->of('student::user.student.create', compact('student'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(StudentUserWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $student = $this->repository->create($attributes); return redirect(trans_url('/user/student/student')) -> with('message', trans('messages.success.created', ['Module' => trans('student::student.name')])) -> with('code', 201); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Student $student * * @return Response */ public function edit(StudentUserWebRequest $request, Student $student) { Form::populate($student); return $this->theme->of('student::user.student.edit', compact('student'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Student $student * * @return Response */ public function update(StudentUserWebRequest $request, Student $student) { try { $this->repository->update($request->all(), $student->getRouteKey()); return redirect(trans_url('/user/student/student')) ->with('message', trans('messages.success.updated', ['Module' => trans('student::student.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(StudentUserWebRequest $request, Student $student) { try { $this->repository->delete($student->getRouteKey()); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('student::student.name')]), 'code' => 202, 'redirect' => trans_url('/user/student/student/0'), ], 202); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }