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

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

laravel5.3軟刪除

2019-11-11 06:44:06
字體:
供稿:網(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ā)表
主站蜘蛛池模板: 长汀县| 深水埗区| 若尔盖县| 泰州市| 山东省| 新干县| 康保县| 碌曲县| 德安县| 平南县| 奎屯市| 武乡县| 阜城县| 富源县| 红安县| 青冈县| 彰化县| 普陀区| 江津市| 微山县| 湛江市| 普宁市| 靖安县| 洪雅县| 郸城县| 寻甸| 连城县| 莱芜市| 新乐市| 公安县| 兰州市| 洞口县| 凤山县| 开阳县| 安图县| 瓦房店市| 罗平县| 印江| 巴南区| 加查县| 望奎县|