Code snippets
Code snippets
Copy-ready answers to everyday coding questions, each with a short explanation. Laravel, PHP, JavaScript, SQL, Bash and more.
2 snippets tagged #delete · Show all
PHP
November 2, 2026
Laravel soft deletes: delete, restore and query trashed records
Marks a row as deleted instead of removing it, so you can restore it later. withTrashed() and onlyTrashed() let you query deleted rows.
<?php
// migration
$table->softDeletes();
SQL
October 20, 2026
MySQL find and delete duplicate rows keeping the lowest id
Finds rows that repeat a column value and deletes all but the one with the smallest id. Run the SELECT first to preview what will be removed, and back up the ta...
-- Preview duplicates
SELECT email, COUNT(*) AS total
FROM users
GROUP BY email