使用Eloquent删除
$contact = Contact::find(5);
$contact->delete();Contact::destroy(1);
// or
Contact::destroy([1, 5, 7]);Contact::where('updated_at', '<', now()->subYear())->delete();Last updated
$contact = Contact::find(5);
$contact->delete();Contact::destroy(1);
// or
Contact::destroy([1, 5, 7]);Contact::where('updated_at', '<', now()->subYear())->delete();Last updated
Schema::table('contacts', function (Blueprint $table) {
$table->softDeletes();
});<?php
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Contact extends Model {
use SoftDeletes; // use the trait
protected $dates = ['deleted_at']; // mark this column as a date
}$allHistoricContacts = Contact::withTrashed()->get();if ($contact->trashed()) {
// do something
}$contact->restore();
// or
Contact::onlyTrashed()->where('vip', true)->restore();$contact->forceDelete();
// or
Contact::onlyTrashed()->forceDelete();