jeudi 24 août 2017

Laravel `insertGetId` doesn't accept empty array

I am using Laravel's insertGetId method to insert a record and get back that record's ID. However, the record I am creating has no properties aside from the auto-incrementing ID. So I pass in an empty array:

$entityId = DB::table('entities')->insertGetId([]);

However this throws the error below:

[Illuminate\Database\QueryException]
SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near ")"
LINE 1: insert into "entities" () values () returning "id"
                              ^ (SQL: insert into "entities" () values () returning "id")

How can I use the insertGetId method for a record that has no properties other than the auto-incrementing ID?

For reference, here is the schema:

Schema::create('entities', function(Blueprint $table) {
  $table->increments('id');
  $table->timestamps();
});



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2vtJYlP
via IFTTT

Aucun commentaire:

Enregistrer un commentaire