repository = $fine; $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->pushCriteria(new \Asadi\Fine\Repositories\Criteria\FineUserCriteria()); parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(FineRequest $request) { $fines = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('fine::fine.names')); return $this->theme->of('fine::user.fine.index', compact('fines'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Fine $fine * * @return Response */ public function show(FineRequest $request, Fine $fine) { Form::populate($fine); return $this->theme->of('fine::user.fine.show', compact('fine'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(FineRequest $request) { $fine = $this->repository->newInstance([]); Form::populate($fine); $this->theme->prependTitle(trans('fine::fine.names')); return $this->theme->of('fine::user.fine.create', compact('fine'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(FineRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $fine = $this->repository->create($attributes); return redirect(trans_url('/user/fine/fine')) -> with('message', trans('messages.success.created', ['Module' => trans('fine::fine.name')])) -> with('code', 201); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Fine $fine * * @return Response */ public function edit(FineRequest $request, Fine $fine) { Form::populate($fine); $this->theme->prependTitle(trans('fine::fine.names')); return $this->theme->of('fine::user.fine.edit', compact('fine'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Fine $fine * * @return Response */ public function update(FineRequest $request, Fine $fine) { try { $this->repository->update($request->all(), $fine->getRouteKey()); return redirect(trans_url('/user/fine/fine')) ->with('message', trans('messages.success.updated', ['Module' => trans('fine::fine.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(FineRequest $request, Fine $fine) { try { $this->repository->delete($fine->getRouteKey()); return redirect(trans_url('/user/fine/fine')) ->with('message', trans('messages.success.deleted', ['Module' => trans('fine::fine.name')])) ->with('code', 204); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }