【发布时间】:2019-11-03 07:48:42
【问题描述】:
我有一个带有语言列“lang”的帖子表,我想只显示会话中存储的语言的帖子。
但我一直得到的只是默认语言(Fr)的帖子
控制器:
public function index(Request $request)
{
if ($request->session()->has('en')) {
$posts = Post::where('lang','=','En')
->with('author','tags','category','comments')
->latestFirst()
->filter(request()->only(['term', 'year', 'month']))
}
elseif ($request->session()->has('ar')) {
$posts = Post::where('lang','=','Ar')
->with('author','tags','category','comments')
->latestFirst()
->filter(request()->only(['term', 'year', 'month']))
}
else {
$posts = Post::where('lang','=','Fr')
->with('author','tags','category','comments')
->latestFirst()
->filter(request()->only(['term', 'year', 'month']))
}
return view("blog.index", compact('posts'));
}
【问题讨论】:
标签: php laravel session controller multilingual