How to Fetch Todays Records From Database In Laravel

Hello artisan,

In this example, I will show you how to fetch today's records in laravel. I will use carbon to show you the way of fetching todays record in laravel. If you don't know how to fetch today's record using carbon in laravel then this example is for you.

Let assume we have a date column in our table and we have to fetch today's record from this table. How we can write this query to fetch. I will show you an eloquent query using carbon to fetch today's record.

Example query:

use Illuminate\Support\Facades\Route;

Route::get('/', function () {

   return Transaction::where('date',\Carbon\Carbon::today())->get();
   
});

 

Read also: How to Get Last N Days Records in Laravel

 

Hope it can help you.

 

Facebook Github
A web enthusiastic, a self-motivated full-stack software engineer from Dhaka, Bangladesh with experience in developing applications using Laravel , React and Vue js