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