Hello Dev today now in this post i will show you How to get last 30 days record in laravel? On this article i goes to details describe on laravel get last 30 days records. I will explain simply about how to get last 30 days data from a table in laravel. In this article, i will implement to get last 30 days records in laravel. i will use laravel to get last 30 days record from database.
i can easily get last 30 days record from database by using laravel 6, laravel 7 and laravel 8 version.
i will show you very simple code of controller method. Where i write code to getting last 30 days records using carbon laravel eloquent.
Read Also : How to use Union query with Laravel Eloquent?
let’s see our controller code:
Controller File:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Carbon\Carbon; class UserController extends Controller { /** * Write code on Method * * @return response() */ public function index() { $date = Carbon::now()->subDays(30); $users = User::where('created_at', '>=', $date)->get(); dd($users); } }
I hope it will help you. Also you can follow us on Facebook