Home / Snippets / How to Alias Column Name in Laravel Eloquent
How to Alias Column Name in Laravel Eloquent cover

How to Alias Column Name in Laravel Eloquent

1.2K

3 years ago

0 comments

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,
}
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

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

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this