I am using the pluck method to retrieve values. How can I translate these values? (these values are options for a selection input field)
$relationtypes = Relationtype::pluck('name', 'id');
My relationtypes are: supplier, customer, etc.
I am using the pluck method to retrieve values. How can I translate these values? (these values are options for a selection input field)
$relationtypes = Relationtype::pluck('name', 'id');
My relationtypes are: supplier, customer, etc.
I also found a more convenient solution:
Passing this to your view, you can use:
Hope this helps other people!
Your controller method may look like:
In your view iterate over them:
If you want to translate the values using the
trans
function you'll need to have beforehand the values inresources\lang\<locale>\<file>.php
For example, lets image the values from your database are:
Then in
resources\lang\nl\slugs.php
This approach is good for non dynamic values, if your values are dynamic the translation probably must be in some db field like:
name_nl
,name_en
maybe?But there are lots of packages for this problem already.