Laravel delete all rows older than 30 days
Laravel delete all rows older than 30 days
In this session, we will try our hand at solving the "Laravel delete all rows older than 30 days".
You can delete all rows from table which are 30 days older from current date. You can use whereDate() and whereRaw() SQL query method to delete the records from table.-
Laravel eloquent to delete 30 days older records from today's date
- whereRaw() SQL Query to delete 30 days older records.
$users = \App\Models\User::whereRaw('DATEDIFF(NOW(), created_at) > 30')->delete(); dd($users);
- whereDate() method to delete 30 days older records from table.
$users = \App\Models\User::whereDate('created_at', '<=', now()->subDays(30))->delete(); dd($users);
It will delete all the records which are 30 days older from today's date and return the number of records as output deleted from table. You can use any of them to get the 30 days older records from the particular table.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Laravel API response format
- Rename Pivot Table in Laravel
- Laravel create multiple records in Pivot table
- Update if exist else insert new record in laravel
- How to get images from AWS s3 and display in Laravel blade
- How to Get records between two dates in Laravel
- How to get id of next record in laravel
- How to add unique records in pivot columns of Laravel pivot table
- Composer\Exception\NoSslException
- How to get specific columns using Laravel eloquent methods
- Target class [App\Http\Controllers\Auth\Request] does not exist.
- Create project factory and seed data in laravel
- Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement
- Target class [admin] does not exist.
- Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0"
- How to create project_user pivot table in laravel
- Laravel save object to database
- Get previous date data in laravel
- Insert dummy data in users table Laravel
- Laravel 10 starter app using breeze on live server
- Setup laravel project with docker
- Docker important commands to run laravel application with docker
- Method Illuminate\Events\Dispatcher::fire does not exist
- Fatal error: Uncaught Error: Class "Illuminate\Foundation\Application" not found
- PhpMyAdmin - Error The mysqli extension is missing