国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 齐齐哈尔市| 巴林右旗| 清苑县| 闵行区| 梅州市| 洛浦县| 桃源县| 普陀区| 新闻| 资溪县| 贡嘎县| 沁水县| 安多县| 那坡县| 四会市| 永定县| 肇东市| 金秀| 内乡县| 张北县| 贞丰县| 江西省| 兖州市| 哈密市| 平和县| 汕头市| 六枝特区| 肃宁县| 汉寿县| 阿城市| 宣化县| 和平县| 林西县| 嘉禾县| 交城县| 广德县| 琼海市| 永新县| 全州县| 利川市| 道孚县|