Model Events. https://laravel.com/docs/5.2/eloquent#events
Doing something on Model creation
Note: I'm good with PHP and pretty OK with traditional inheritance-based OOP, but an struggling with what seems to be some pretty basic stuff in Laravel.
I have a Week model, and a Day model. Whenever I get a an instance of a Week I want to subsequently be able to do something like :
$week = new Week( <some attribtues> );
foreach (Week->days as $day) {
<some code>
}
How can I create the days (even if they are not currently created) whenever I get a week? And how do I make sure that the days are returned as part of the Week model?
I can kinda see how I can do this using logic in a controller, but it doesn't seem to be the right place.
I can kinda see how I can create the days using events, but I don't then see how to get the days back into the Model.
This seems like a pretty basic thing to want to do: created some related objects whenever you create an object. But I'm really struggling.
Any advice?
Please or to participate in this conversation.