Hi everyone, I have two tables and destroy raw of table A with eloquent, and delete related raw in table B, what is the best way to do that? I don't want to write two delete methods for both A and B tables, because I want to delete In some controllers.
thanks
You can use Eloquent's delete() method to delete a row from both tables. You can also use Eloquent's destroy() method to delete multiple rows from both tables.
For example, if you have a User model and a Post model, and you want to delete a user and all of their posts, you can do the following:
@sahar_mkr this will delete all Thing model instances where the user_id matches the User record that has been deleted. In your PHP code, you need only to delete the User instance (in this example).
$user->delete();
if I want to insert a model and its relations what can I do?