let's suppose I have two related models. It's a one-to-many relationship. One teacher can have many students but every student is assigned to only one teacher. If I now want to update the relationship I did something like this so far:
Ok, this works but to me it's kind of hacky. I'd rather have a sync() method like with many-to-many relationships. An unwanted side effect of this method is also that it will very quickly increase your autoincremented id. I have a vue frontend that autosaves on updating data, so there is a lot of updates going on. Is there a special reason Laravel doesn't provide a synch method for this kind of relationship? And do you have any idea how to do this cleverly?
thanks for the quick reply. The stackoverflow answer really looks like what I need. However I'm quite new to Laravel and I'm not sure how to implement that. Where would I put the file containing the HasManySyncable class and where to put the abstract class file? And then would all my models extend the abstract MyBaseModel to make use of the functionality?
You got it right. So he created the file within app/Models/Relations directory, you can see that from the namespace in the class. But you can put it wherever it works for you. And then yes, you should create an abstract BaseModel class and extend it from a model which you would like to use the sync function for. In your case I believe it should be the Student model.