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 form request validation
- Composer create project laravel/laravel example app
- Post model with title and body in laravel 8
- SQLSTATE[42000]: Syntax error or access violation: 1055
- Declaration of App\Models\Post::sluggable() must be compatible with Cviebrock\EloquentSluggable\Sluggable
- Rename Pivot Table in Laravel
- How to get file extension from input type file in laravel
- Always load the relationship data with eager loading in Laravel
- OrderBy on Eloquent relationships method in Laravel
- Call to a member function pluck() on null
- Array to string conversion laravel blade
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.post_id' in 'where clause
- How to insert value to additional columns in pivot table in laravel
- Ajax POST request in laravel
- How to use bootstrap pagination in laravel 8
- How to automatically update the timestamp of parent model in Laravel
- How to check query string exists or not in laravel blade
- Route group with URI prefix using middleware and route name prefixes
- Send id with route Laravel
- How to restore multiple records after soft-deletes in Laravel
- Add [name] to fillable property to allow mass assignment on [App\Models\Project]
- Get current URL on visit URL in Laravel
- How to display validation error in laravel
- How to pass variable from controller to model in Laravel
- How to disable timestamps in laravel