Delete Records Older Than 30 Days in Laravel?

Posted by

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.



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
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x