Guest User

Untitled

a guest
Jan 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. ///ClienteController.php
  2.  
  3.  
  4. public function destroy($id)
  5. {
  6. $cli = Cliente::find($id);
  7. $cli->delete();
  8.  
  9.  
  10. return redirect()->route('cliente.index');
  11. }
  12.  
  13.  
  14.  
  15. //No model Cliente.php
  16.  
  17.  
  18. public function delete()
  19. {
  20. //Apaga os relacionados aqui
  21. $clicnpj = ClienteCNPJ::where('Cliente_ID', $this->Cliente_ID)->get();
  22.  
  23. foreach($clicnpj as $cn) {
  24. $cn->delete();
  25. }
  26.  
  27. $cliop = ClienteOperacao::where('Cliente_ID', $this->Cliente_ID)->get();
  28.  
  29. foreach($cliop as $cp) {
  30. $cp->delete();
  31. }
  32. parent::delete();
  33. }
Add Comment
Please, Sign In to add comment