Илья Алисов
Илья Алисов

Reputation: 434

Laravel Pivot table without model

I have the model Banner and array of allowed locales.

What I want is to assing Banner to multiple languages, for example Banner can show in 'en','ru' locales, but not visible in 'de' locale.

locales are storing in config file - `app('config.allow_languages')

How can I create relation with Banner and locales through pivot table, without creating locales table and model

Upvotes: 0

Views: 316

Answers (1)

Thiago Meireles
Thiago Meireles

Reputation: 171

If I understand correctly, without creating other models/tables, I would:

Create the model Banner, having the 'locale' column in json/jsonb format.

Then, in every place you need to get the banner, use a where clause, like:

Banner::whereJsonContains('locale', app('config.allow_languages'));

If it works the way you want, you could make a scope where this 'where' runs everytime you use the Banner model.

Upvotes: 1

Related Questions