Closed rezaffm closed 2 years ago
I am not 100% sure if that did the trick, but it doesn't look too bad either, can you please advise?
public function scopeWithUniqueSlugConstraints(Builder $query, Model $model, $attribute, $config, $slug)
{
return $query
->where('entryable_type', $model->entryable_type)
->whereHas('entryable', function($query) use ($model) {
$query->where('locale', $model->entryable->locale);
});
}
Hello,
I have a polymorphic model called "entry", like:
which is used for Posts, Pages, Reviews et cetera, for example:
(using polymorphism to achieve Multitable Inhertiance).
As you can see, the "locale" lives on Posts, Reviews et cetera.
What now gives me a hard time is, how to set up scopeWithUniqueSlugConstraints, because it needs to be dependent upon the entryable_type and locale, which however lives on $model->entrayable, which sometimes it a post, a review ot something else.
How to correctly set it up in this case?
It is relevant for cases, where you have a review on a product, for instance "Apple Iphone", that should be reviewed in English and let's say in German. Therefore, the generated slug should be the same in both languages.
Any help would be greatly appreciated.