Skip to content
Discussion options

You must be logged in to vote

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 the hasTranslations trait.

public function getTitlesAttribute($value)
{
    return json_decode($this->getRawOriginal('title'), true);
}

So, your $thesi->translations->titles will be an array of the type

[
    "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 a…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@matej-1234
Comment options

Answer selected by matej-1234
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants