1

In the following:

DB::table('users')
    ->join('item', 'users.id', '=', 'item.user_id')
    ->select('item.name')
    ->get();

Is there a way to reference 'item.name' as just 'name'?

1 Answer 1

3

Sure. You need to use either DB::raw or selectRaw

select(DB::raw('item.name AS name'))

Or

selectRaw('item.name AS name')
Sign up to request clarification or add additional context in comments.

2 Comments

If there's more than one would it look like this? selectRaw('item.name AS name', 'item.name2 AS name2')?
No. You need to pass them as string selectRaw('item.name AS name, item.name2 AS name2')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.