Is there any way how to display all languages from one column on blade ? #326
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Ah nice , i figured it out by my own, here is the solution: |
Beta Was this translation helpful? Give feedback.
-
Hello. You can also create a mutator like this one (note the "s" at the end of "titles"). public function getTitlesAttribute($value)
{
return json_decode($this->getRawOriginal('title'), true);
} So, your [
"sk" => "sk text",
"en" => "en text"
] So, in your blade file you can print something like @foreach($thesi->translations->titles as $title)
<span>{{ $title }}</span><br>
@endforeach And your output HTML would be <span>sk text</span><br>
<span>en text</span><br> Maiking it dynamic you will be able to add new languages without having to edit your code at all. |
Beta Was this translation helpful? Give feedback.
Hello.
You can also create a mutator like this one (note the "s" at the end of "titles").
The
getRawOriginal
method will let you get the column value without the casting made by thehasTranslations
trait.So, your
$thesi->translations->titles
will be an array of the typeSo, in your blade file you can print something like
And your output HTML would be
Maiking it dynamic you will be able to a…