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.

 

#laravel #eloquent-tips