這是最後一個問題,我問更新多行不同的ID ..如何Laravel
我有一個會員表
Schema::create('role_memberships', function (Blueprint $table) {
$table->increments('id');
$table->integer('role_id');
$table->string('MembershipName');
$table->text('MembershipValue');
$table->timestamps();
});
我有同樣的ROLE_ID和我的兩個數據要更新兩行 這是我的控制器
$updateArray = [['MembershipValue' => $request->PostAdMaxImage],
['MembershipValue' => $request->PostAdExpiredDay]];
DB::table('role_memberships')->where('role_id', $id)-
>whereIn('role_id', $role->pluck('id'))->update($updateArray);
,當我嘗試更新,我得到了一個錯誤數組字符串轉換..
你可以發佈你的錯誤?和$ role-> pluck('id')返回數組,因爲whereIn將數組作爲2個參數。 ex( - > whereIn('id',[1,2,3])) – LorenzoBerti
@LorenzoBerti我使用ajax更新..所以,錯誤只顯示在檢查元素 –
'foreach($ updateArray as $ array){ ('role_id',$ id) - >其中('role_id',$ role-> pluck('id')) - > update($ array); }' –