
Laravel delete where condition
Laravel delete where condition
With this article, we’ll look at some examples of how to address the "Laravel delete where condition" problem.
You can delete the records from users table using where condition.Basically where condition filter the data and delete the records. Like if you want to delete all the records except the record of user id 1 than you can use where('id', '>', 1)->delete()
to delete the record.
-
$deleted = DB::table('users')->where('id', '>', 1)->delete();
This query will delete all the users records except the user id 1.
Import DB facade in controller class after namespace
use Illuminate\Support\Facades\DB;
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
- Php artisan make model, factory, migration and controller in single command
- Syntax error or access violation: 1072 Key column 'role_id' doesn't exist in table (SQL: alter table `users` add constraint `users_role_id_foreign` foreign key (`role_id`) references `roles` (`id`))
- Laravel get count with where condition
- How to get last record from object collection in laravel
- How to fill a column automatically while creating records in Laravel
- Validation errors for multiple forms on same page Laravel
- How to get last month records in Laravel
- Get laravel version
- File_put_contents(/var/www/html/w3code/storage/framework/sessions/CXwN3EXKxERD6jgy3rADcaAAbAx8FRKih2JK7UO9): Failed to open stream: Permission denied
- Where to use whereNotNull eloquent in laravel
- Method Illuminate\Events\Dispatcher::fire does not exist
- How to pass query string to url in laravel
- How to Get records between two dates in Laravel
- Laravel delete all rows older than 30 days
- How to create pivot table in laravel using migration
- Rendering HTML from database table to view in Laravel
- Laravel create multiple records in Pivot table
- Permission denied error while creating storage link in Laravel
- How to upload multiple images after preview in laravel using cropper js
- Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0"
- Get latest record by created at in Laravel
- Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given
- Recursive function example code PHP Laravel
- Generate random string lowercase in Laravel
- Create record with unique slug in laravel