I'm trying to refactor my project from having all code under the App folder into seperate composer packages. However I've hit a blocker which I could use some input to solve:
To simplify I'd like to create 2 packages, Core
and Customers
. I want Core
to be fully seperated, having no references to any of my other packages. Inside Core
there is a model called Business
, and in Customer
there is a model called Customer
. There is a many-to-one relation ship between the models. The problem arises when I want to create the Eloquent relationship methods. Customer
is dependant on Core
, so this is not an issue, $this->belongsTo(Business::class)
. However, to get the inverse Core
needs to know about the Customer
model, $this->hasMany(Customer::class)
.
Is there a way around this? Like maybe registering a method on the Business
model from my Customer
package? Or have I gotten it all backwards?
EDIT
For those not familiar with Laravel, a relationship is defined as a function in the model class
class Business extends Model {
public function customers() {
return $this->hasMany(Customer::class);
}
}