
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
- Laravel get all records with pagination
- Laravel change date format
- Get last week data in Laravel
- Method Illuminate\Http\Request::validated does not exist
- How to set column as primary key in Laravel model
- The Pusher library requires the PHP cURL module. Please ensure it is installed
- Undefined property: stdClass::$title
- Property [user] does not exist on this collection instance
- Multiple Level eager loading in Laravel
- Laravel 5.4 save data to database
- Laravel get single row by id
- Show old value while editing the form in Laravel
- How to check relationship is loaded or not in Laravel
- Retain selected value of select box in Laravel
- Send post data from controller to view
- RuntimeException You must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
- Global scope in Laravel with example
- How to get last year records count with month wise in Laravel
- How to call controller function from view in Laravel
- Create project factory and seed data in laravel
- How to get records in random order in laravel
- Laravel recursive function in controller
- Laravel hasmany select not working
- Post model with title and body in laravel 8
- How to get IP address in laravel