Search code examples
selectlaravelaliaseloquentlaravel-3

Laravel 3 Eloquent How to select column as


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!


Solution

  • 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'));