ItSolutionStuff.com

How to Get Last 30 Days Record in Laravel?

By Hardik Savani • April 16, 2024
Laravel

This article goes in detailed on laravel get last 30 days records. i explained simply about how to get last 30 days data from a table in laravel. In this article, we will implement a get last 30 days records in laravel. We will use laravel get last 30 days data from database.

we can easily get last 30 days records in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 version.

i will show you simple code of controller method where we written code to getting last 30 days records using carbon laravel eloquent.

let's see 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 can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel Eloquent firstOrNew Example

Read Now →

Laravel Eloquent Delete Record By ID Example

Read Now →

Laravel Eloquent inRandomOrder() Method Example

Read Now →

Laravel Eloquent whereNull() Query Example

Read Now →

Laravel Eloquent whereBetween() Query Example

Read Now →

Laravel Eloquent whereRaw Condition Example

Read Now →

Laravel Collection Merge | How to Merge Two Eloquent Collection?

Read Now →

How to use whereHas with orWhereHas in Laravel?

Read Now →

Laravel One to One Eloquent Relationship Tutorial

Read Now →

Laravel Where Condition with Two Columns Example

Read Now →