Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

I guess it is totally normal behaviour as models are not purged after they are deleted from the database. You could propably refresh your relation also by calling:

$document->segments()->get()

but like I said this is pretty standard that relation models classes are not deleted when row in database is deleted.

0

I'm not sure but maybe this is your answer.
'segments()' is a function in your Document class. If you call it like $document->segments() you actually call that function and get a new QueryBuilder.
When calling 'segments' the object checks if the required data is allready laded. If yes it is returned, otherways it is queried from the database (like calling ->get() for the query).
$document->segments()->delete() will create a query which deletes the data in the database but it doesn't check the loaded data.
$document->segments->delete() should check the loaded data. If or not loaded it will be emptied and a query to the database will be send to clear it.

I could easily be wrong so please reply after you check it.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.