I have a column named "name" in my database table hold JSON value like that:
{"en":"Morocco","ar":"المغرب"}
I want to access this value automatically depending on the current language by just writing: $country->name
on my view, Thanks.
I have a column named "name" in my database table hold JSON value like that:
{"en":"Morocco","ar":"المغرب"}
I want to access this value automatically depending on the current language by just writing: $country->name
on my view, Thanks.
You can do this using accessors. In your Country Eloquent Model, add this:
public function getNameAttribute($value) {
$name = json_decode($value, true);
return $name[app()->getLocale()];
}