Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. cliente
  2. id: NOT NULL AUTOINCREMENT PK,
  3. nome: VARCHAR(100),
  4. idade: INT,
  5. cpf: VARCHAR(11)
  6.  
  7. class Medidor extends Model
  8. {
  9. protected $table = 'medidor';
  10. public $timestamps = false;
  11. }
  12.  
  13. public function salvar(Request $request){
  14. try{
  15. $cliente = new Cliente( );
  16. $cliente->nome = $request->input('nome');
  17. $cliente->idade = $request->input('idade');
  18. $teste = $cliente->save();
  19.  
  20. $obj = array(
  21. 'retorno' => true,
  22. 'msg' => 'Operação realizada com sucesso!'
  23. );
  24.  
  25. return response()->json($obj, 200);
  26. }catch(Exception $exception){
  27. $obj = array(
  28. 'retorno' => false,
  29. 'log' => 'Error: '.$exception->getMessage(),
  30. 'msg' => 'Não foi possível salvar. '
  31. );
  32. return response()->json($obj, 400);
  33. }
  34. }
  35.  
  36. $.ajax({
  37. url: acao,
  38. type: "post",
  39. dataType: "json",
  40. data: {
  41. id: 0,
  42. nome: 'Cliente',
  43. idade: 15
  44. }
  45. }).done( r => {
  46. console.log('r',r)
  47. if( r.retorno ){
  48. console.log('Deu certo')
  49. }
  50. }).fail((t)=>{
  51. console.log('Deu erro')
  52. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement