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