How to use Fluent Query Builder in laravel

Fluent is the query builder class of Laravel . Fluent Query Builder handles base database query actions using PHP Data Objects in the backend, and it can be used with almost any database driver. Let’s say that you need to change the database driver from SQLite to MySQL; if you’ve written your queries using Fluent, then you mostly don’t need to rewrite or alter your code unless you’ve written raw queries using DB::raw(). Fluent handles this behind the scenes.

Let’s take a quick look at the Eloquent Model of Laravel 4 (which can be found in the Vendor\Laravel\Framework\src\Illuminate\Database\Query folder):

<?php namespace Illuminate\Database\Query;

use Closure;
use Illuminate\Support\Collection;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Database\Query\Grammars\Grammar;
use Illuminate\Database\Query\Processors\Processor;

class Builder {
    //methods and variables come here

As you can see, the Eloquent Model uses some classes, such as Database, ConnectionInterface, Collection, Grammar, and Processor. All of these are required to standardize database queries in the backend, cache the queries if required, and return the output as a collection object.

About the author

Deven Rathore

I'm Deven Rathore, a multidisciplinary & self-taught designer with 3 years of experience. I'm passionate about technology, music, coffee, traveling and everything visually stimulating. Constantly learning and experiencing new things.

Pin It on Pinterest


Get the best in web dev

Join and recieve best in web dev , once a week FREE

An email has been Sent to your Inbox ! Please Confirm your Subscription :)