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