How to Select Certain Fields in Laravel Eloquent?

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Master Selecting Specific Fields Using Laravel Eloquent Introduction: In your quest to become a skilled Laravel developer, you're bound to encounter situations where you need to select specific fields from database tables in your applications. This blog post aims to provide guidance on how you can achieve this using Laravel Eloquent, the elegant object-relational mapping (ORM) layer provided by the Laravel framework. 1. Understanding Eloquent Laravel's Eloquent is a powerful tool that allows you to interact with database tables in your application. It provides an easy and expressive way to access, create, update, and delete records from relational databases using PHP objects. 2. Selecting Specific Fields Using Laravel Eloquent To select specific fields from a table using Eloquent, you can use the 'select' method followed by the field names. Let's take an example:
$categories = CategoryModel::where('catType', '=', 'Root')
                    ->select('catID', 'catName', 'imgPath');
In this scenario, you are fetching records from the "categories" table and filtering out those with a "catType" set to "Root". You can see that we have included 'catID', 'catName' and 'imgPath' as our selected fields. The 'select' method ensures that only these three columns will be returned in each row of our result set. Alternatively, if you need all the available columns from a specific table (like categories), use the '*' wildcard:
$categories = CategoryModel::where('catType', '=', 'Root')
                    ->select(DB::raw('*'));
3. Understanding LaravelQueryBuilder Laravel's Eloquent ORM is built on top of QueryBuilder, which provides a simple yet flexible way to perform database queries using plain PHP code without dealing with SQL directly. By combining the power of both Eloquent and QueryBuilder, you can achieve more advanced functionality in your application.
$categories = DB::table('categories')
                   ->where('catType', '=', 'Root')
                   ->select('catID', 'catName', 'imgPath');
In the above example, we're using Laravel's QueryBuilder to perform a query with selected fields directly. Note that this approach may be more suitable when dealing with raw database queries. You can also use SQL functions such as DB::raw() or subqueries in your select statement. 4. Conclusion Now you understand how to select certain fields from Laravel Eloquent models by using the "select" method and combining it with where clauses. By leveraging both QueryBuilder and Eloquent ORM, you can craft powerful database queries that fetch only the necessary data for your application while maintaining a clean code base. Remember to follow best practices for performance and maintainability when writing your database queries. As always, test and optimize query performance if needed to ensure a smooth user experience for your application.