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