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