Mrtvac's avatar

history() method in Eloquent

Hi,

I couldn't find any documentation for history() method except this one:

// Force deleting all related models... $flight->history()->forceDelete();

How will this work? Will this work with softDeletes also? I've try above method but I got error that history() couldn't be find in DB Query.

0 likes
6 replies
bobbybouwmann's avatar

Laravel doesn't have a history model. Are you referring to a relation with a History model?

Mrtvac's avatar

This is from Laravel 5.1 documentation

Sometimes you may need to truly remove a model from your database. To permanently remove a soft deleted model from the database, use the forceDelete method:

// Force deleting a single model instance...
$flight->forceDelete();

// Force deleting all related models...
$flight->history()->forceDelete();

So, I'm interested, what does this history() method do? As I couldn't find any other info about that method.

Mrtvac's avatar

Hahahaha :) So sorry. Just realized, this is just example how to delete related models :)))

Silly me :))

1 like
sfsccn's avatar

Years later this confused me as well. To be clear, history is just a made-up Flight relationship used for illustration purposes in the v7 soft query docs, similar to the phone example here. It is not part of Eloquent.

padawanTony's avatar

Years later, this confused me as well. They should replace the history() method with something more clear.

2 likes

Please or to participate in this conversation.