Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- public function store(Request $request)
- {
- $validated = $request->validate([
- 'nome' => 'required',
- 'tel' => 'required',
- 'cpf' => 'required',
- 'placa' => 'required'
- ]);
- DB::beginTransaction();
- try {
- //Espaço para tratar alguma lógica, ex:
- $validated['tel'] = Helper::formatarTelefone($request->tel);
- //Nome de model não pode ser no plural
- $newCliente = Clientes::create($validated);
- DB::commit();
- return response()->json([
- 'status' => true,
- 'notification' => '... realizado com sucesso.',
- 'data' => new ClientesResource($newCliente)
- ], 201);
- } catch (Exception $e) {
- DB::rollback();
- return response()->json([
- 'status' => false,
- 'notification' => $e->getMessage()
- ]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement