Posts Learn Components Snippets Categories Tags Tools new About
/

How to Alias Column Name in Laravel Eloquent

Learn how to rename / alias column name when querying with Laravel Eloquent

Created on Jul 10, 2021

309 views

Aliasing/renaming column name is quite straightforward to do in Laravel Eloquent. You can alias a column name when you perform a "select" query.

Post::select(['id as the_id'])->first();

By doing so the result will be as follows.
App\Models\Post {#4736
    the_id: 3,
}

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Load comments for How to Alias Column Name in Laravel Eloquent

)