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