DEV Community

Cover image for How to Get Last 7 Days Record in Laravel
Saddam Hossain
Saddam Hossain

Posted on

How to Get Last 7 Days Record in Laravel

In this tutorial i will show you, How to Get Last 7 Days Record in Laravel application. This simple article demonstrates of laravel get last 7 days records. i explained simply about get last 7 days data in laravel. i explained simply step by step get last 7 days records in laravel. In this article, we will implement a laravel get last 7 days data from database.

we can easily get last 7 days records in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 version. You Can Learn How to Generate and Read Sitemap XML File in Laravel 11 Tutorial

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

How to Get Last 7 Days Record in Laravel Example:

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(7);
        $users = User::where('created_at', '>=', $date)->get();
        dd($users);

    }

}

Enter fullscreen mode Exit fullscreen mode

Read More Tutorials From DevScriptSchool.Com

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay