Correction status:qualified
Teacher's comments:
thinkphp 模型的闭包查询和软删除
application\index\controller\Demo.php
<?php namespace app\index\controller; use think\Controller; use app\index\model\Comment as CommentModel; class Demo extends Controller { public function query() { $comment=CommentModel::all(function($query){ $query->where('id','<',3); }); dump($comment); echo '<hr>'; } public function softDelete() { CommentModel::destroy(4); $res=CommentModel::onlyTrashed()->select(); dump($res); } } ?>
点击 "运行实例" 按钮查看在线实例
application\index\model\Comment.php
<?php namespace app\index\model; use think\Model; use think\model\concern\SoftDelete; class Comment extends Model { // use SoftDelete; protected $table='comment'; protected $pk='id'; protected $deleteTime='delete_time'; protected $defaultSoftDelete=0; }
点击 "运行实例" 按钮查看在线实例
softdelete.png
query.png