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

首頁 > 學院 > 開發設計 > 正文

laravel5.3軟刪除

2019-11-11 05:33:59
字體:
來源:轉載
供稿:網友

1、首先在模型中要使用SoftDeletestrait,該trait為軟刪除提供一系列相關方法,具體可參考源碼Illuminate/Database/Eloquent/SoftDeletes ,此外還要設置$date屬性數組,將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、向數據庫中的相應數據表添加 delete_at 字段

#生成一個遷移文件php artisan make:migration add_deleted_at_to_users_table --table=users #執行遷移文件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(); }); } #模型里面執行delete方法就行了 self::whereIn('id', $ids)->delete(); //刪除用戶 withTrashed() 顯示所有數據 onlyTrashed() 顯示刪除數所 restore()還原數據
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 山东| 安吉县| 手游| 讷河市| 达尔| 祁门县| 双流县| 莒南县| 绥阳县| 广德县| 简阳市| 大同市| 常熟市| 自贡市| 五莲县| 义乌市| 偏关县| 新化县| 兖州市| 扎鲁特旗| 岳池县| 会宁县| 温宿县| 武宁县| 达孜县| 汾西县| 桐城市| 从化市| 务川| 乳山市| 云和县| 惠来县| 汕尾市| 德昌县| 武冈市| 柘荣县| 平果县| 岑巩县| 永平县| 扎鲁特旗| 慈利县|