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