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