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