Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

yonka's avatar
Level 2

Restore or Permanantly Delete using Query Builder not eloquent

I want to be able to restore or permanently delete soft deleted record by using Query Builder not Eloquent

0 likes
2 replies
LaryAI's avatar
Level 58

To restore or permanently delete a soft-deleted record using Laravel's Query Builder, you can directly interact with the database using SQL queries. Here's how you can achieve both actions:

Restoring a Soft Deleted Record

To restore a soft-deleted record, you need to set the deleted_at column to NULL. Here's an example using Query Builder:

use Illuminate\Support\Facades\DB;

DB::table('your_table_name')
    ->where('id', $recordId) // Replace $recordId with the ID of the record you want to restore
    ->update(['deleted_at' => null]);

Permanently Deleting a Soft Deleted Record

To permanently delete a soft-deleted record, you can simply delete the record from the database:

use Illuminate\Support\Facades\DB;

DB::table('your_table_name')
    ->where('id', $recordId) // Replace $recordId with the ID of the record you want to delete
    ->delete();

Notes

  • Replace your_table_name with the actual name of your table.
  • Replace $recordId with the ID of the record you want to restore or delete.
  • Ensure that your table has a deleted_at column if you are using soft deletes.

These operations bypass Eloquent's built-in soft delete functionality, so use them with caution to ensure data integrity.

Snapey's avatar

why?

You can interract with soft deleted models using eloquent. What is the actual problem you are trying to solve?

1 like

Please or to participate in this conversation.