last insert id mysql laravel code example
Example 1: Get last id in laravel
$last3 = DB::table('items')->latest('id')->first();
Example 2: laravel query builder get last insert id
$id = DB::table('users')->insertGetId(
['email' => '[email protected]', 'votes' => 0]
);
Example 3: laravel db insert get last id
$id = DB::table('users')
->insertGetId(
['name' => 'Akash Savani', 'email'=>'[email protected]']
);
Example 4: Get last id in laravel
$last2 = DB::table('items')->orderBy('id', 'DESC')->first();