laravel get id of inserted record code example
Example 1: laravel db insert get last id
$id = DB::table('users')
->insertGetId(
['name' => 'Akash Savani', 'email'=>'[email protected]']
);
Example 2: laravel get last id
DB::table('myTable')->orderBy('id','desc')->first();
Example 3: laravel get ID from insert
$data = User::create(['name'=>'first']);
dd($data->id);
Example 4: Get last id in laravel
$last = DB::table('items')->latest()->first();