Lang在laravel不能在控制器上工作,从ajax返回查看
问题描述:
lang multi Language in laravel not work in controller.I use ajax query database in Controller,I need to use lang in controller return to view but output not translate Language such as
controller
public function a2($id)
{
echo '<h1>'.@lang('home.text').'</h1>';
echo '<p>content from query data</p>';
}
ajax
success: function (data) {
document.getElementById("response").innerHTML = data;
}
html
<div id="response"></div>
output
@lang('home.text')
content from query data
答
@lang() is for blade, use __()
public function a2($id)
{
echo '<h1>'.__('home.text').'</h1>';
echo '<p>content from query data</p>';
}
答
You can use __
helper function in controllers:
public function a2($id)
{
echo '<h1>'. __('home.text').'</h1>';
echo '<p>content from query data</p>';
}
答
Can you try this
Lang::get('home.text')
instead of
@lang('home.text')