How to get last 30 days record in laravel?

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Hello Dev
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

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →