Categories

Thursday, April 18, 2024
#919814419350 therichposts@gmail.com
Laravel

laravel scheduler with delete query

Laravel 7.2 routing with route group auth guard check with prefix

laravel scheduler with delete query

Hello to all, welcome to therichpost.com. In this post, I will tell you, laravel scheduler with delete query.

Your task schedule is defined in the app/Console/Kernel.php file’s schedule method. Laravel scheduler is the very feature of laravel which makes cron jobs easy to handle and code.

Here is example working query for laravel scheduler with delete query:
$schedule->call(function () {

$now = \Carbon\Carbon::now();


DB::table('notifications')
             ->where('created_at', '<', $now->subDays(15))//I am deleting the 15 days old notifications
             ->delete();

    })->daily();
}
If you want to start the scheduler itself then you will have to add one cron job on server using the crontab -e command:
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1

If you have any query related to this post then please do comment.

 

 

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.