laravel get data from last 7 days – How to Get Last 7 Days Record in Laravel?

laravel get data from last 7 days using Carbon::now()->subDays(7) and ->whereRaw(‘DATE(join_date) = DATE_SUB(CURDATE(), INTERVAL 7 DAY)’) Examples.

laravel get data from last 7 days

i can easily get last 7 days records in laravel 6, laravel 7 and laravel 8 version. it should be last N days records.

Controller File:


namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Carbon\Carbon;
class MemberController extends Controller
     * Write code on Method
     * @return response()
    public function index()
        $date = Carbon::now()->subDays(7);
        $Members = Member::where('join_at', '>=', $date)->get();

You can use whereDate for that :

->whereDate('join_at', Carbon::now()->subDays(7))

Example 2

 ->whereRaw('DATE(join_date) = DATE_SUB(CURDATE(), INTERVAL 7 DAY)')

Don’t Miss : Laravel Get Last 7 Days Month Year Record From MySQL?

I hope you get an idea about laravel get data from last 7 days.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.