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