Blogger Information
Blog 56
fans 3
comment 1
visits 50670
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
thinkphp 模型的闭包查询和软删除——2018年5月25日
沈斌的博客
Original
1548 people have browsed it

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

softDelete.png

query.png

query.png

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post