如何从一个Laravel中的多个实例中分离一个实例|雄辩的枢纽表? [英] how to detach one instance from multiple in a laravel | Eloquent pivot table?

查看:69
本文介绍了如何从一个Laravel中的多个实例中分离一个实例|雄辩的枢纽表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据透视表:"bonus_circle"具有具有相同circle_id和bonus_id的多个项目的功能.换句话说,同一个圈子可能有多个相同的奖金.使用$ circle-> bonuses()-> detach($ id)删除所有实例.我只需要分离一个实例就可以了.有人知道可以解决这个问题吗?

Pivot Table: 'bonus_circle' has the ability to have multiple items with the same circle_id and bonus_id. In other words There can be multiple of the same bonuses associated with the same circle. Using $circle->bonuses()->detach($id) removes ALL of the instances. I need it to only detach ONE instance. Does anyone know a work around for this?

推荐答案

Raw Query目前可以使用,但是如果有人可以回答这个问题,我将不胜感激.

Raw Query works for now, but if anyone can answer this i would appreciate it.

DB::delete('DELETE FROM bonus_circle WHERE bonus_id = ? AND circle_id = ? LIMIT 1',[$bonus->id, $circle->id]);

这篇关于如何从一个Laravel中的多个实例中分离一个实例|雄辩的枢纽表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆