Hello @kartik,
Firstly create an object, Then set attributes value for that object, Then save the object record, and then get the last inserted id. such as
$user = new User();
$user->name = 'Niroj';
$user->save();
// Now Getting The Last inserted id
$insertedId = $user->id;
echo $insertedId ;
Hope it helps you!!