第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

軟刪除:

首先在模型里面引用SoftDelete
<?php
namespace?app\index\model;
use?think\Model;
use?traits\model\SoftDelete;
class?User?extends?Model{
????use?SoftDelete;
????#autowritetimestamp表示創(chuàng)建與更新的時(shí)間戳都被打開
????protected?$autoWriteTimestamp?=?true;
????#刪除數(shù)據(jù)的時(shí)候刪除時(shí)間戳默認(rèn)寫入字段delete_time中,當(dāng)要自定義時(shí):
//????protected?$deleteTime?=?'自定義刪除時(shí)間字段名';
}

然后在控制器里面執(zhí)行操作

<?php
namespace?app\index\controller;
use?think\Controller;
use?app\index\model\User;
class?Index?extends?Controller
{
????public?function?index(){
//????????$res?=?User::destroy(4);//被軟刪除
//????????$res?=?User::get(2);//返回NULL

????????#查詢包含已刪除的數(shù)據(jù)
????????//$res?=?User::withTrashed(true)->find(2);

????????#查詢僅包含已刪除的數(shù)據(jù)
????????$res?=?User::onlyTrashed()->select();
????????foreach?($res?as?$val){
????????????dump($val);
????????}
????????#若要恢復(fù)被軟刪除的數(shù)據(jù),直接用update方式將delete_time的值設(shè)置為NULL即可

????????#當(dāng)開啟軟刪除后要想真正徹底刪除數(shù)據(jù),在destroy的第二個(gè)參數(shù)后面?zhèn)魅胍粋€(gè)true值
????????$res?=?User::destroy(1,true);

????????#通過(guò)get方式進(jìn)行軟刪除/刪除
????????$res?=?User::get(3);//如果此處數(shù)據(jù)已經(jīng)被軟刪除則獲取到的為NULL,后面的操作無(wú)效
????????$user->delete();//軟刪除
????????$res?=?$user->delete(true);//刪除
????}
}


1
采集 1

快速入門ThinkPHP 5.0 --模型篇

  • 難度中級(jí)
  • 時(shí)長(zhǎng) 3小時(shí) 0分
  • 人數(shù)27162
  • 評(píng)分9.7

一個(gè)標(biāo)準(zhǔn)的網(wǎng)站一定離不開數(shù)據(jù)庫(kù)的操作,在本套課程中我和你一起來(lái)揭開ThinkPHP5 數(shù)據(jù)操作的神秘面紗,和你一起愉快的使用 ThinkPHP5 操作數(shù)據(jù)庫(kù),讓數(shù)據(jù)庫(kù)操作變的更愉悅。

烏云龍 PHP開發(fā)工程師

愛拼 專注 才會(huì)贏

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)