国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

laravel5.3軟刪除

2019-11-11 06:08:05
字體:
供稿:網(wǎng)友

1、首先在模型中要使用SoftDeletestrait,該trait為軟刪除提供一系列相關(guān)方法,具體可參考源碼Illuminate/Database/Eloquent/SoftDeletes ,此外還要設(shè)置$date屬性數(shù)組,將deleted_at置于其中:

<?phpnamespace App/Model/Backend;use App/Http/Response;use Illuminate/Database/Eloquent/Model;use Illuminate/Database/Eloquent/SoftDeletes;use Request;class User extends Model{ use SoftDeletes; PRotected $table = 'users'; //表名 protected $primaryKey = 'id'; //主鍵 protected $datas = ['deleted_at'];

2、向數(shù)據(jù)庫中的相應(yīng)數(shù)據(jù)表添加 delete_at 字段

#生成一個遷移文件php artisan make:migration add_deleted_at_to_users_table --table=users #執(zhí)行遷移文件php artisan migrate<?php use Illuminate/Database/Schema/Blueprint; use Illuminate/Database/Migrations/Migration; class AlterPostsDeletedAt extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::table('posts', function (Blueprint $table) { $table->softDeletes(); }); } #模型里面執(zhí)行delete方法就行了 self::whereIn('id', $ids)->delete(); //刪除用戶 withTrashed() 顯示所有數(shù)據(jù) onlyTrashed() 顯示刪除數(shù)所 restore()還原數(shù)據(jù)
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 哈尔滨市| 蒲江县| 吉水县| 盖州市| 布尔津县| 漠河县| 南昌市| 河东区| 永修县| 栾川县| 沙湾县| 涿州市| 华坪县| 苏州市| 兴山县| 麟游县| 延安市| 昌宁县| 松潘县| 信宜市| 通化市| 平果县| 望奎县| 瓦房店市| 华坪县| 荔波县| 南汇区| 来安县| 西华县| 凭祥市| 景德镇市| 三门峡市| 黄梅县| 北安市| 新密市| 呼和浩特市| 马山县| 五大连池市| 简阳市| 久治县| 隆化县|