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 = 'John';
$user->save();
Now getting the last inserted id
$insertedId = $user->id;
echo $insertedId ;
Hope it is helpfull!!
Thank you!!