Posts Learn Snippets Categories Tags 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


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,

Created by

PostSrc poster


Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.