Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
Yes, you can. But I'm not sure if this is necessary in your case. I needed it because I had to work with an already existing table structure. I did this: The base class of the model, from which the other two are inherited. The base class has this structure:
protected static function boot()
{
parent::boot();
if (static::TYPE) {
static::addGlobalScope('type_scope', function (Builder $builder) {
$table = $builder->getModel()->getTable();
$builder->where("{$table}.type", '=', static::TYPE);
});
}
}
For the main entities represented by independent classes - it's not worth it, the headache will be more than good.
But for auxiliary ones (for example, for storing data attached to instances of different file classes) - it is used with might and main and is described in the documentation as Polymorphic Relationships.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question