Laravel 3 Eloquent How to select column as

darksoulsong picture darksoulsong · Sep 4, 2013 · Viewed 16.3k times · Source

I'm trying to figure out how to give a column an alias using Eloquent.

So, in other words, how do I execute the following mysql query using Eloquent?

SELECT occupation AS test FROM users WHERE occupation = 'PIMP';

Thx in adv!

Answer

amosmos picture amosmos · Oct 28, 2013

Eloquent returns a regular Fluent query. So you can try something like this (assuming your model name is 'User'):

$user = User::where_occupation('pimp')->get(array('occupation as test'));