How to create Laravel Model without Eloquent?
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
How to Create Laravel Models Without Eloquent: Diving into Raw Database Interaction
As a senior developer, I often see developers asking this exact question: "Can I build my data layer in Laravel without relying on Eloquent? I want to understand exactly what's happening under the hood and avoid the abstraction of an ORM."
The short answer is yes, it is absolutely possible. While Eloquent ORM is the most popular and powerful way to handle database interactions in Laravel, the framework provides lower-level tools that allow you to interact directly with the database using raw SQL queries. This approach gives you maximum control over performance and data manipulation, which is crucial for highly optimized applications.
This post will explore how you can manage your data structures and create logic akin to models without invoking Eloquent, focusing on using Laravel's native database tools.
Understanding the Trade-off: ORM vs. Raw SQL
Eloquent (and other ORMs) provide a beautiful abstraction layer. They map database tables directly to PHP objects, handle relationships automatically, manage mass assignment protection, and simplify complex queries into elegant method calls. This is fantastic for rapid development.
However, this abstraction comes with a trade-off: overhead. When you bypass Eloquent, you are responsible for managing the hydration of results (converting rows into meaningful PHP objects), handling error checking manually, and writing all your SQL yourself. This shifts the responsibility from the framework to you, offering raw speed at the cost of boilerplate code.
Direct Database Interaction using the DB Facade
Instead of using the Eloquent Model syntax (User::where(...)), we utilize Laravel's built-in DB facade or the underlying Illuminate\Database\Eloquent\Model methods if we are dealing with raw query building. For pure, un-modeled interaction, we rely on the explicit query builder.
Let’s look at how you fetch data directly from the database:
<?php
namespace App\Services;
use Illuminate\Support\Facades\DB;
class UserRepository
{
/**
* Fetches all users by ID using raw SQL execution.
*
* @param int $userId
* @return array
*/
public function findUsersRaw(int $userId): array
{
// Execute a SELECT statement directly and fetch the results as an array.
$results = DB::select('SELECT * FROM users WHERE id = ?', [$userId]);
// The result is an array of standard PHP objects/arrays, not Eloquent models.
return $results;
}
/**
* Inserts a new record without using a Model.
*
* @param array $data
* @return bool
*/
public function insertRawData(array $data): bool
{
// Use the insert method for bulk or simple insertions.
$inserted = DB::table('products')->insert($data);
return $inserted;
}
}
As you can see, by using DB::select() or DB::table(), we bypass the Eloquent Model entirely. We are executing SQL commands directly and receiving the results as raw data structures (arrays of objects). This is the essence of working without an ORM.
Structuring Data Without Models
If you choose not to use Eloquent models, how do you maintain structure? The solution lies in creating dedicated Service Classes or Repository classes. These classes become your custom "models" for business logic and data access. They encapsulate the raw SQL execution and handle the mapping of results into strongly typed PHP arrays that your application can consume.
For complex operations involving multiple tables, this is where the power of raw SQL shines. You gain full control over joins, subqueries, and complex aggregations without fighting against an ORM’s conventions. When managing extremely high-throughput systems or highly specialized data structures, this level of direct access becomes a significant advantage.
Conclusion: When to Choose Which Path?
Creating models without Eloquent is technically feasible by leveraging the raw database layer provided by Laravel. This path offers unparalleled control and performance optimization, making it ideal for niche scenarios, complex reporting queries, or legacy system integrations where the overhead of an ORM is deemed unnecessary.
However, as a general rule for most standard CRUD (Create, Read, Update, Delete) applications, sticking with Eloquent remains the recommended approach. It significantly reduces development time and cognitive load. Use raw SQL when performance profiling dictates it, or when you are building highly customized data access layers that require deep interaction with database features. Always remember that Laravel provides robust tools for both methodologies; we simply choose the right tool for the job.