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