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