Search code examples
laravellaravel-8laravel-9

How to access the Id's of both tables which is identical in Laravel view


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.


Solution

  • 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;
    }