HI, Ive got a system that Im building for a advertising company and they sell advertising a Medical Centres and Real Estates , So I created a Site model then then created Two Subclasses called MedicalSite and MovingSite. using Global scope classes.
So when I want a medical or moving (real estate) site I can just use the correct class but what I would like to do is have the correct site returned.
So my idea was to create a resolving binding and then in the callback I can check the site type and return the correct class so when I call Site::find(1)
I should get a MedicalSite instance back as site id 1 is a medical Site.
This is just a first example of the function I came up with but It not working but It is being called
$this->app->afterResolving('Apps4u\Sharples\Models\Site', function($site){
if($site->id){
if($site->site_type == 'medical') {
dd('med');
return new MedicalSite($site->toArray());
}
if($site->site_type == 'moving') {
dd('med');
return new MovingSite($site->toArray());
}
}
});
Ive tried resolving and afterResolving both functions get called but the inner if statements dont fire.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community