in Laravel documentation i found detach() method to detach all objects in many to many relationships. Can detach() method also be applied to one to many relationship in Laravel? if not, how can I detach all n objects in this case?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
In many to many relationships, detach() method only delete pivot entry in your database, except if you have specific cascade deleting.
For one to many relationship, you want to use dissociate() method to unbind the relation and associate() to bind it on the belongsTo Side.
On the contrary, you would add account using attach() on the hasMany side:
To delete all comments you would do :
More info here: https://laravel.com/docs/5.6/eloquent-relationships
From the docs