Laravel Delete Query Builder

Laravel provides a clean and fluent API for building database queries using Eloquent ORM or the Query Builder. When it comes to deleting records from your database, Laravel makes it very straightforward.

In this blog, we’ll explore how to use the Laravel Query Builder to delete records with real examples.

Why Use Query Builder for Deleting Records?

  • It’s faster and more lightweight than Eloquent for simple delete operations.
  • Ideal for bulk deletes or where you don’t need model events or relationships.
  • Easier to write and debug raw SQL-like queries in Laravel style.

Delete Using Query Builder

Delete Using Query Builder

Query Builder is a lightweight and fast way to perform database operations directly without loading models.

Syntax :-

DB::table(‘table_name’)->where(‘condition’)->delete();

Example 1: Delete a Blog Post by ID.

DB::table(‘blogs’)->where(‘id’, 5)->delete();

Example 2: Bulk Delete Based on a Condition.

DB::table(‘blogs’)->where(‘status’, ‘draft’)->delete();

Important Notes Using Query Builder

  • No soft deletes (deleted_at is ignored)
  • No Eloquent events (deleting, deleted)
  • Faster for bulk deletes

Delete Using Eloquent ORM

Eloquent is Laravel’s ActiveRecord implementation and provides a model-centric approach, with support for soft deletes, model events, and relationships.

Syntax :-

Model::find($id)->delete();

Example 1: Delete a Blog Post by ID

use App\Models\Blog;
$blog = Blog::find(5);
$blog->delete();

Example 2: Bulk Delete with Conditions

Blog::where(‘author_id’, 3)->where(‘status’, ‘archived’)->delete();

With Soft Deletes :-

use Illuminate\Database\Eloquent\SoftDeletes;
class Blog extends Model{
use SoftDeletes;
}

Important Notes Using Eloquent ORM

  • Soft Delete Support
  • Model Events (deleting, etc.) Support
  • Relationships Fully Supported.

Conclusion

Use Query Builder for fast and simple deletes, especially for bulk operations.
Choose Eloquent when you need soft deletes, relationships, or model events.

Pick the method that fits your use case – performance or model-driven logic.
And always handle deletes with care, especially in production!

Need Help With Laravel Development?

Work with our skilled Laravel developers to accelerate your project and boost its performance.

Support On Demand!