join('moreusers', 'use...">

Laravel 4: query builder retrieves join table data

In Laravel, we could join two tables with this:

DB::table("users")->join('moreusers', 'users.id', '=', 'moreusers.user_id')->get();

And extract the data using this:

$querydata[$i]->email

If both tables contain the same column name, how can I get it from the first and second table?

Thank.

+3
source share
1 answer

Use method select():

DB::table("users")
    ->join('moreusers', 'users.id', '=', 'moreusers.user_id')
    ->select('users.email as user_email', 'moreusers.email as other_email')
    ->get();
+1
source

All Articles