repository = $student; parent::__construct(); } /** * Display a list of student. * * @return Response */ public function index(StudentRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('student::student.names')); return $this->theme->of('student::admin.student.index')->render(); } /** * Display a list of student. * * @return Response */ public function getJson(StudentRequest $request) { $pageLimit = $request->input('pageLimit'); $students = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Assetdocs\\Student\\Repositories\\Presenter\\StudentListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $students['recordsTotal'] = $students['meta']['pagination']['total']; $students['recordsFiltered'] = $students['meta']['pagination']['total']; $students['request'] = $request->all(); return response()->json($students, 200); } /** * Display student. * * @param Request $request * @param Model $student * * @return Response */ public function show(StudentRequest $request, Student $student) { if (!$student->exists) { return response()->view('student::admin.student.new', compact('student')); } Form::populate($student); return response()->view('student::admin.student.show', compact('student')); } /** * Show the form for creating a new student. * * @param Request $request * * @return Response */ public function create(StudentRequest $request) { $student = $this->repository->newInstance([]); Form::populate($student); return response()->view('student::admin.student.create', compact('student')); } /** * Create new student. * * @param Request $request * * @return Response */ public function store(StudentRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $student = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('student::student.name')]), 'code' => 204, 'redirect' => trans_url('/admin/student/student/'.$student->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show student for editing. * * @param Request $request * @param Model $student * * @return Response */ public function edit(StudentRequest $request, Student $student) { Form::populate($student); return response()->view('student::admin.student.edit', compact('student')); } /** * Update the student. * * @param Request $request * @param Model $student * * @return Response */ public function update(StudentRequest $request, Student $student) { try { $attributes = $request->all(); $student->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('student::student.name')]), 'code' => 204, 'redirect' => trans_url('/admin/student/student/'.$student->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/student/student/'.$student->getRouteKey()), ], 400); } } /** * Remove the student. * * @param Model $student * * @return Response */ public function destroy(StudentRequest $request, Student $student) { try { $t = $student->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('student::student.name')]), 'code' => 202, 'redirect' => trans_url('/admin/student/student/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/student/student/'.$student->getRouteKey()), ], 400); } } }