How to Get Today's Records in Laravel
In this lesson, we will see how to retrieve only today's records from the database in Laravel, let's assume that we have an e-commerce website and we want to get the orders done today.
Get today's orders
So to get today's orders we use the following eloquent model query:
<?php
namespace App\Http\Controllers\Admin;
use Carbon\Carbon;
use App\Models\Order;
use App\Http\Controllers\Controller;
class AdminController extends Controller
{
/**
* Get today's orders
*/
public function index()
{
return view('admin.index')->with([
'todayOrders' => Order::whereDay('created_at', Carbon::today())->get()
]);
}
}