这是最后一个问题,我问更新多行不同的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); }' –