How to change database column name in Eloquent query results
Often times, developers are required to output query results with a specific column name (other than what is in the database table). In order to set specific name of the column column in the results use “as” in the eloquent query.
Example code:
$users = DB::table('users')
->select('name', 'email as username')
->get();
In the above example, result will show column name as username instead of email.
Published by:
Laravel Fan