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

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

laravel5.3軟刪除

2019-11-11 07:31:44
字體:
供稿:網(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 字段

#生成一個(gè)遷移文件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ā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 龙井市| 平陆县| 天长市| 手游| 望城县| 丁青县| 德钦县| 马边| 洪江市| 奉化市| 永清县| 孝义市| 金山区| 大理市| 星座| 洪泽县| 秭归县| 庆云县| 土默特右旗| 沁阳市| 扶余县| 永清县| 武邑县| 石景山区| 墨脱县| 哈尔滨市| 南京市| 博乐市| 琼中| 霍林郭勒市| 宁乡县| 兴安盟| 武穴市| 泗水县| 五莲县| 湟源县| 即墨市| 兰州市| 临猗县| 吴桥县| 涪陵区|