Skip to content

Instantly share code, notes, and snippets.

@systemseven
Created June 12, 2013 13:50
Show Gist options
  • Save systemseven/5765439 to your computer and use it in GitHub Desktop.
Save systemseven/5765439 to your computer and use it in GitHub Desktop.
Soft Deletes in Laravel 4
//in the model
class User extends Eloquent {
protected $softDelete = true;
}
//in the migration, to create a soft delete column
$table->softDeletes();
//to force query to return the deleted items
$users = User::withTrashed()->where('account_id', 1)->get();
//to have query return ONLY the deleted items
$users = User::onlyTrashed()->where('account_id', 1)->get();
//to undelete a soft deleted model
$user->restore();
//or use the restore method on a query
User::withTrashed()->where('account_id', 1)->restore();
//to full delete, not soft delete
$user->forceDelete();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment