亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

雄辯的updateOrCreate總是創建

雄辯的updateOrCreate總是創建

PHP
狐的傳說 2021-04-26 16:29:16
我正在嘗試使用updateOrCreate簡化我的代碼,但是該功能始終會創建一個新行,永遠不會更新。我的遷移:        Schema::create('logs', function (Blueprint $table) {         $table->bigIncrements('id');         $table->integer('project_id')->unsigned();         $table->datetime('is_fixed')->nullable();         $table->datetime('snooze_until')->nullable();         $table->integer('snooze_while')->nullable();         $table->string('title', 100);         $table->string('level', 100);         $table->string('description');         $table->string('stage',100);         $table->json('details')->nullable();         $table->timestamps();         $table->foreign('project_id')->references('id')->on('projects');        });我的$ fillablesprotected $fillable = [    'project_id',     'is_fixed',     'snooze_until',     'snooze_while',     'title',     'level',     'description',     'stage',    'details'];我的測試    $log = new Log();    $log->fill([        'title' => 'Vicente\\Sally\\Schiller',        'level' => 'ERROR',        'description' => 'Laboriosam et architecto voluptatem.',        'stage' => 'production@wender-fedora',        'details' => '{"app":"MyApp"}',        'project_id' => 5    ]);    Log::updateOrCreate($log->toArray());我有一些可為空的字段,但我認為這不是問題。
查看完整描述

2 回答

?
三國紛爭

TA貢獻1804條經驗 獲得超7個贊

您想嘗試以下一種方法:


    Log::updateOrCreate(

        [

            'title' => 'Vicente\\Sally\\Schiller',

            'project_id' => 5

        ], 

        [

            'title' => 'Vicente\\Sally\\Schiller',

            'level' => 'ERROR',

            'description' => 'Laboriosam et architecto voluptatem.',

            'stage' => 'production@wender-fedora',

            'details' => '{"app":"MyApp"}',

            'project_id' => 5

        ]

    );


查看完整回答
反對 回復 2021-05-14
  • 2 回答
  • 0 關注
  • 180 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號