Eloquent模型类默认白名单属性为空,黑名单默认属性为*
,即所有字段都不会应用批量赋值:
//使用批量赋值的属性
protected $fillable = [];
//不使用批量赋值的属性
protected $guarded = [‘*‘];
所谓软删除只是给记录打上一个 ·已删除·的标记,不再出现在查询结果中。
判断一条记录是否被软删除 trashed
$post = Post::findOrFail(1);
$post->delete();
if ($data->trashed())
{
dump(‘已删除‘);
}
只获取被软删除的记录 onlyTrashed
$post = Post::onlyTrashed()->where(‘views‘,0)->get();
恢复被软删除的数据restore
$post->restore();
执行物理删除,从数据表删除 forceDelete
$post->forceDelete();
原文:https://www.cnblogs.com/bigcola/p/13387678.html