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