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のテーブルとの関係のみが削除されます。$idtwo_model$two_id
one_model
$id
two_model
$two_id
詳細については、ここをクリックしてください。