nifCody nifCody - 3 years ago 122
PHP Question

Passing parameter through @lang method in laravel 5.4

Translating some cities in the local array need to make some problem on Laravel 5.4. I try the following way but it is failed.

$popular_cities = ['log_angel','new_york','colombo'];

@foreach ($popular_cities as $city)
<li><a href="">@lang('ui.{{$city}}')</a></li>
@endforeach


but it is failed to show the name as mentioned in my language file

ui.php in lang directory



<?php
return [
'log_angel' => 'Los Angel',
'new_york' => 'New York',
'colombo' => 'Colombo'
];
?>

Answer Source

Since you are in Blade function, only use :

<li><a href="">@lang('ui.'. $city)</a></li>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download