Laravel 12 Eloquent Delete Query By id Example

In Laravel 12, you can delete a record using Eloquent by its `id` in several ways. Below are different approaches.

1. Using `find()` and `delete()` Method

<?php
use App\Models\User;

$user = User::find(1); // Find user by ID
if ($user) {
$user->delete(); // Delete the user
}
?>

2. Using `destroy()` Method (Multiple IDs Supported)

<?php
use App\Models\User;
User::destroy(1); // Delete user with ID 1

// Delete multiple users
User::destroy([2, 3, 4]); 
?>

3. Using `where()` and `delete()`

<?php
use App\Models\User;
User::where('id', 1)->delete(); // Delete user with ID 1
?>

4. Using Query Builder

<?php
use Illuminate\Support\Facades\DB;

DB::table('users')->where('id', 1)->delete(); // Delete user with ID 1
?>

Each of these methods effectively deletes records from the database. The `destroy()` method is useful for deleting multiple records, while `where()` allows conditional deletions.