A
A
Anatoly2018-07-08 16:00:08
ORM
Anatoly, 2018-07-08 16:00:08

How to write scope in a model to select a field by condition?

Hello guys!
Actually, there is a table
there is a table:

=========================================
| id  |  title_ru | title_en | title_kz |
=========================================

The question is how, when referring to the
$record->title model element or let it be scope, $record->title()
, he himself understood which language I want to choose:
now I do this right in the template:
$title = 'title_' . LaravelLocalization::getCurrentLocale();
($record->$title) ? $record->$title : $record->title_ru;

but ideally it would be like this:
$record->title
How to implement it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question