Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我尝试了以下方法:
$one = OneModel::findOrFail($id); $two = $one->two_model()->findOrFail($two_id); $two->delete();
但这会从数据库中删除记录,我怎样才能删除关系而不从表中删除?而且也不必弄乱数据透视表,因为如果需要,我为什么还要使用框架......
如果我理解正确,detach()您正在寻找的是:
detach()
$one = OneModel::findOrFail($id); $one->two_model()->detach($two_id);
这将仅删除数据透视表中与one_model'table's$id和two_model'table's的关系。$two_id
one_model
$id
two_model
$two_id
点击这里了解更多详情。