Insert data into Oracle table "without returning id into"?

1

I'm using Laravel 5.2 and when I enter data it wants to return the last, but at the moment I want to insert and know if the operation was successful. My function in controller looks like this:

public function cadastrar(),
{
        $codigo= Request::input('codigo');
        $codigo1 = Request::input('codigo1');

        $model= new ModelCriado();
        $model->CD_SEQUENCIA   = "SEQUENCIA.NEXTVAL";
        $model->CD_CODIGO      = $codigo;
        $model->CD_CODIGO1     = $codigo1;
        $model->save();
        return response()->json( array( "response" => 1 ) );
    }

But he is giving this message:

  

Error Code: 904       Error Message: ORA-00904: "ID": invalid identifier       Position: 128       Statement: insert into model values (: p0,: p1,: p2) returning id into: p3       Bindings: [SEQ_MODEL.NEXTVAL, 759,123,0]

My table only has 3 columns

CD_SEQUENCIA, CD_CODIGO, CD_CODIGO1

How do I resolve this?

  

EDITION 1

class ModelCriado extends Model
{
    protected $table = "model_criado";
    public $timestamps = false; 
}
    
asked by anonymous 19.10.2017 / 20:16

1 answer

1

Well, since your bank is the field CD_SEQUENCIA , it is the field that has its value generated by the database, so try setting Model to your $primaryKey :

class ModelCriado extends Model
{
    protected $table = "model_criado";
    public $timestamps = false;    
    protected $primaryKey = 'CD_SEQUENCIA';
    protected $fillable = ['CD_CODIGO', 'CD_CODIGO1'];
}

and try inserting with the code below:

public function cadastrar()
{
    $codigo= Request::input('codigo');
    $codigo1 = Request::input('codigo1');

    $model= new ModelCriado();  
    $model->CD_CODIGO = $codigo;
    $model->CD_CODIGO1 = $codigo1;
    $model->save();
    return response()
          ->json( array( "response" => 1 ) );
}

public function cadastrar()
{
    $codigo= Request::input('codigo');
    $codigo1 = Request::input('codigo1');

    $model= new ModelCriado();  
    $model->CD_CODIGO = $codigo;
    $model->CD_CODIGO1 = $codigo1;
    $model->save();
    return response()
          ->json( array( "response" => 1 ) );
}

or

public function cadastrar()
{
    $codigo= Request::input('codigo');
    $codigo1 = Request::input('codigo1');

    $model = ModelCriado::create(Request::all());   

    return response()
          ->json( array( "response" => 1 ) );
}

or

public function cadastrar()
{
    $codigo= Request::input('codigo');
    $codigo1 = Request::input('codigo1');

    $model = new ModelCriado(Request::all());   
    $model->save();

    return response()
          ->json( array( "response" => 1 ) );
}

or

public function cadastrar()
{
    $codigo= Request::input('codigo');
    $codigo1 = Request::input('codigo1');

    $model = new ModelCriado();
    $model->fill(Request::all());
    $model->save();

    return response()
          ->json( array( "response" => 1 ) );
}
    
19.10.2017 / 21:00