I take it boot()
is invoked once only, the first time this object is instantiated. It means events can be set up only if needed, so helping performance. That's my understanding.
Hmm, I wonder if this is anything to do with my overriding of the constructor?
Yes, that appears to be it. As is often the case, you can't see the wood for the trees until you try to explain it to someone else. To fix this, the constructor of my adapter must call the constructor of the parent model. It does not need to pass any data to it; it just needs to make sure it is called.
class OrderAdapter extends Order
{
parent::__construct(); // Events are set up in here
public function __construct($source_data)
{
$this->name = $source_data['order_name'];
// etc.
}
}
I override the constructor in the first place because instantiating an Order
through the OrderAdapter
involves passing it initial data in a completely different form from the format normally expected by an Eloquent model. In this case, it's data from a WooCommerce API call that scans for new orders on remote shops, and is a stdClass
and needs some translations of some properties and further API lookups of others.
Off topic but I prefer to use observers instead of the boot method http://laravel.com/docs/4.2/eloquent#model-observers
I don't know, it just seems cleaner to keep those events out of the model
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community