skip to Main Content

My Model is:

<?php

namespace App;

use IlluminateDatabaseEloquentModel;

class PedidoCliente extends Model
{
    protected $primaryKey = 'pdc_id';
    protected $table = 'scs_pedido_cliente';
}

My method is:

DB::beginTransaction();
try {

    $pedido                      = new PedidoCliente();
    $pedido->pdc_cod             = 1
    $pedido->pdc_cli_cod         = 1;
    $pedido->pdc_tpgp_cod        = 1;
    $pedido->pdc_total_frete     = 99;
    $pedido->pdc_total_com_frete = 199;
    $pedido->pdc_desc            = 'Compra produto x';
    $pedido->pdc_data_insert     = date("Y-m-d H:i:s");
    $pedido->save();
    DB::commit();

 } catch (Exception $e) {
    DB::rollback();
}

Don’t return errors. I see the object and Primary Key when I print:

echo "<pre>";
print_r($pedido);
die("</pre>");

but it doesn’t save in database.

2

Answers


  1. Chosen as BEST ANSWER

    I found the problem. A transaction had started in another function and it was not closing.


  2. In catch, you need to echo

    echo $e->getMessage();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search