repository = $requestform; parent::__construct(); } /** * Display a list of requestform. * * @return Response */ public function index(RequestformAdminWebRequest $request) { if ($request->wantsJson()) { $requestforms = $this->repository->setPresenter('\\Litecms\\BenefitCard\\Repositories\\Presenter\\RequestformListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); return response()->json($requestforms, 200); } $this ->theme->prependTitle(trans('benefit_card::requestform.names').' :: '); return $this->theme->of('benefit_card::admin.requestform.index')->render(); } /** * Display requestform. * * @param Request $request * @param Model $requestform * * @return Response */ public function show(RequestformAdminWebRequest $request, Requestform $requestform) { if (!$requestform->exists) { return response()->view('benefit_card::admin.requestform.new', compact('requestform')); } Form::populate($requestform); return response()->view('benefit_card::admin.requestform.show', compact('requestform')); } /** * Show the form for creating a new requestform. * * @param Request $request * * @return Response */ public function create(RequestformAdminWebRequest $request) { $requestform = $this->repository->newInstance([]); Form::populate($requestform); return response()->view('benefit_card::admin.requestform.create', compact('requestform')); } /** * Create new requestform. * * @param Request $request * * @return Response */ public function store(RequestformAdminWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $requestform = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('benefit_card::requestform.name')]), 'code' => 204, 'redirect' => trans_url('/admin/benefit_card/requestform/'.$requestform->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show requestform for editing. * * @param Request $request * @param Model $requestform * * @return Response */ public function edit(RequestformAdminWebRequest $request, Requestform $requestform) { Form::populate($requestform); return response()->view('benefit_card::admin.requestform.edit', compact('requestform')); } /** * Update the requestform. * * @param Request $request * @param Model $requestform * * @return Response */ public function update(RequestformAdminWebRequest $request, Requestform $requestform) { try { $attributes = $request->all(); $requestform->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('benefit_card::requestform.name')]), 'code' => 204, 'redirect' => trans_url('/admin/benefit_card/requestform/'.$requestform->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/benefit_card/requestform/'.$requestform->getRouteKey()), ], 400); } } /** * Remove the requestform. * * @param Model $requestform * * @return Response */ public function destroy(RequestformAdminWebRequest $request, Requestform $requestform) { try { $t = $requestform->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('benefit_card::requestform.name')]), 'code' => 202, 'redirect' => trans_url('/admin/benefit_card/requestform/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/benefit_card/requestform/'.$requestform->getRouteKey()), ], 400); } } }