abstract:<?php namespace app\index\controller; use think\Controller; use app\index\model\Books; class Booksl extends Controller { //查詢 public function Query() { //$res = Books::where('state
<?php
namespace app\index\controller;
use think\Controller;
use app\index\model\Books;
class Booksl extends Controller
{
//查詢
public function Query()
{
//$res = Books::where('state',1)->select();//查詢構造器方法查詢
$res = Books::all(function($query)
{
$query->where('state',1)->order('id','desc');//使用閉包查詢
});
var_dump($res);
}
//添加
public function Create()
{
$data=[
"title"=>'php精通到放棄',
"brief"=>'為什么要學php能?作為世界上最好的語言,可以讓你變成高薪白領。但是你需要努力學習',
"author"=>'大哥大',
"state"=>0
];
Books::create($data);
}
//修改
public function Update()
{
$id = 1;
$author = '嘻嘻洗';
$state = 1;
Books::update(['author'=>"$author",'state'=>"$state"],function($query) use($id){
$query->where('id',"$id");
});
}
//刪除
public function Delete()
{
$id = 5;
Books::destroy(function($query)use($id){
$query->where('id',"$id");
});
}
//軟刪除
public function SoftDele()
{
$id = 7;
Books::destroy(function($query)use($id){
$query->where('id',"$id");
});
$res = Books::withTrashed()->select();
dump($res);
// Books::destroy(1,true);
// // $res = Books::withTrashed()->select();
// // dump($res);
}
}
Correcting teacher:西門大官人Correction time:2019-05-05 10:27:33
Teacher's summary:所謂軟刪除,實際上就是update記錄的刪除狀態(tài)