Ad

How To Get Last Inserted Auto-incremented Id And Insert It Into Another Table In Laravel?

I have journallog and subjournallog tables. When I insert data in the journallog table, I'd like to get the auto-incremented id from it and insert into the subjournallog table. Can someone provide an example of how to do this?

Ad

Answer

$user = User::create(['emai' => 'EMAIL', 'password' => 'PASSWORD']);

creates the user and returns it. And ID is accessible via $user->id

Ad
source: stackoverflow.com
Ad