I have used join that joins to two tables that has the same id column name, while passing it to the view and how to access the ids of both tables.
You can use SELECT as:
$example = Example::join('example2', 'example2.id, '=', 'example.id')
->select([
'example.id AS id',
'example2.id AS id2'
])
->where('')
->get();
view:
foreach($example as $result)
{
$id = $result->id;
$id2 = $result->id2;
}