mercredi 21 décembre 2016

How to check if model's attached items have changed?

Suppose we have Class and Student models with many-to-many relationship defined between them.

I want to perform some action, if $students, that are attached to a $class, change. For example:

$class->attach($newSetOfStudents); // notify a teacher about the change behind the scenes
$class->save();                    // by overriden save() or attach() methods

How can this be accomplished? I tried to use ..->isDirty() when overriding the save() method, but it does not seem to work with attached models.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire