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