Laravel 5 Lang :: get () Replace
I have a problem's.
You can use Lang :: get () in Laravel 5, I want to do a to replace characters.
resources / languages ββ/ EN / messages.php
<?php
return array(
'test' => 'test message. :name',
view / top.blade.php
{!! App::setLocale('en') !!}
{!! Lang::get('messages.test', array('name' => 'Dayle')) !!}
However, this is a mistake.
ErrorException in Translator.php line 148:
Missing argument 2 for Illuminate\Translation\Translator::Illuminate\Translation\{closure}(), called in /home/my-site/www/my-site/vendor/compiled.php on line 11547 and defined (View: /home/my-site/www/my-site/resources/views/top.blade.php)
Because I do not know.
Don't know who you know?
source to share
I just resolve this issue by following the steps here
To summarize, try the following steps:
- Remove vendor /compiled.php and storage / framework / compiled.php file
- Run it
composer update
, and if it doesn't start automatically, run itphp artisan optimise
again to compile. - Use double quotes in your messages.php file (for example
"title" => "Value in double qoutes"
) - Run
composer dump-autoload -o
source to share
Use parentheses in message.php: 'test' => 'test message. (: Name) ",
Also, looking at your error message, I think that {!! App :: setLocale ('en') !!} in your opinion creates a problem for some reason, so just remove it, it works without it, I tried it.
Optionally, add use \ Lang; in your controller.
source to share
maybe you can try the recommended syntax -> Lang::get('messages.test', ['name' => 'Dayle'])
?
update:
you can also try a helper function:
{{ trans('messages.test', array('name' => 'Dayle')) }}
and remove at the end of that line test' => 'test message. :name',
in
it would also be better App::setLocale('en')
in your controller and not the view, but these are only best practices and probably not the cause of your problem.
source to share