Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel-5 get last inserted id after firstOrCreate()

I'm trying to get the last inserted ID in the database after a firstOrCreate() call. I have copied my code below:

$booking->firstOrCreate(array_slice($reserve->whereId($payment->reserved_place_id)->first()->toArray(), 0, 24))->save();

How can I get the last ID inserted?

I have looked at the other Laravel requests to get last insert ID but I believe this instance is different because they are not using firstOrCreate().

Thanks in advance.

like image 541
V4n1ll4 Avatar asked Dec 25 '22 17:12

V4n1ll4


1 Answers

firstOrCreate() method returns Model. So you can simply save it to some variable and then get the model's ID.

like image 108
Martin Heralecký Avatar answered Dec 28 '22 07:12

Martin Heralecký