repository = $celebs; parent::__construct(); } /** * Display a list of celebs. * * @return json */ public function index(CelebsRequest $request) { $celebs = $this->repository ->setPresenter('\\Celebs\\Celeb\\Repositories\\Presenter\\CelebsListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); $celebs['code'] = 2000; return response()->json($celebs) ->setStatusCode(200, 'INDEX_SUCCESS'); } /** * Display celebs. * * @param Request $request * @param Model Celebs * * @return Json */ public function show(CelebsRequest $request, Celebs $celebs) { $celebs = $celebs->presenter(); $celebs['code'] = 2001; return response()->json($celebs) ->setStatusCode(200, 'SHOW_SUCCESS');; } /** * Show the form for creating a new celebs. * * @param Request $request * * @return json */ public function create(CelebsRequest $request, Celebs $celebs) { $celebs = $celebs->presenter(); $celebs['code'] = 2002; return response()->json($celebs) ->setStatusCode(200, 'CREATE_SUCCESS'); } /** * Create new celebs. * * @param Request $request * * @return json */ public function store(CelebsRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.api'); $celebs = $this->repository->create($attributes); $celebs = $celebs->presenter(); $celebs['code'] = 2004; return response()->json($celebs) ->setStatusCode(201, 'STORE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4004, ])->setStatusCode(400, 'STORE_ERROR'); } } /** * Show celebs for editing. * * @param Request $request * @param Model $celebs * * @return json */ public function edit(CelebsRequest $request, Celebs $celebs) { $celebs = $celebs->presenter(); $celebs['code'] = 2003; return response()-> json($celebs) ->setStatusCode(200, 'EDIT_SUCCESS');; } /** * Update the celebs. * * @param Request $request * @param Model $celebs * * @return json */ public function update(CelebsRequest $request, Celebs $celebs) { try { $attributes = $request->all(); $celebs->update($attributes); $celebs = $celebs->presenter(); $celebs['code'] = 2005; return response()->json($celebs) ->setStatusCode(201, 'UPDATE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4005, ])->setStatusCode(400, 'UPDATE_ERROR'); } } /** * Remove the celebs. * * @param Request $request * @param Model $celebs * * @return json */ public function destroy(CelebsRequest $request, Celebs $celebs) { try { $t = $celebs->delete(); return response()->json([ 'message' => trans('messages.success.delete', ['Module' => trans('celeb::celebs.name')]), 'code' => 2006 ])->setStatusCode(202, 'DESTROY_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4006, ])->setStatusCode(400, 'DESTROY_ERROR'); } } }