Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.



Get Started Now!

Delete Records Older Than 30 Days in Laravel?

Laravel

Let’s examine how Laravel deletes all records that are older than 30 days in this brief example. You can learn how to delete all records older than 30 days in Laravel by using this example. I’ll demonstrate how to delete records older than 30 days in Laravel. You’ll get a straightforward example of how to delete outdated records after 30 days in this article. So let’s develop an example of Laravel that deletes all records older than 30 days by following a few simple steps.

I’ll provide a straightforward database query to erase all entries older than 30 days in your Laravel application if you just want to maintain the most recent 30 days’ worth of data. All you have to do is set up your cron. So let’s examine the straightforward query code.

<?php

     

namespace App\Http\Controllers;

     

use Illuminate\Http\Request;

use App\Models\Post;

     

class PostController extends Controller

{

    

    /**

     * Write code on Method

     *

     * @return response()

     */

    public function index(Request $request)

    {

   

        Post::whereDate('created_at', '<=', now()->subDays(30))->delete();

  

    }

}
0 0 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
trackback

[…] Delete Records Older Than 30 Days in Laravel? […]

1
0
Would love your thoughts, please comment.x
()
x