I try to add value in DB, and after that to get the ID, and to use in another table ,for a column, but it's always null, and I am not sure why.
$lkp_location = new LkpLocation();
if (is_numeric($request->lkp_location_text)) { // If I get number from request, the value exists in DB, Else create and return ID
$lkp_location_id = $request->lkp_location_text;
} else {
$lkp_location->fill([
'text' => $request->lkp_location_text,
])->save();
$lastInsertedId = $lkp_location->id;
$lkp_location_id = $lastInsertedId;
}
dump($lkp_location_id); //It's the ID from DB
$person = new Person();
$person->fill([
//code with another columns...
'lkp_location_id' => $lkp_location_id,
//code with another columns...
]);