php - Laravel Eloquent 返回 null
问题描述
我有 laravel 的多语言网站。我正在为参数传递slug。从 berita 传递到 beritaDetail。但它显示错误,当 dd($berita) 时,只显示 null
$title = "title_".App::getLocale()." as title";
$content = "content_".App::getLocale()." as content";
$slug = "slug_".App::getLocale();
$berita = Report::select("*", "$title", "$content")->where('slug_'.App::getLocale(), $slug)->first();
dd($berita);
$beritaRandom = Report::take(6)->inRandomOrder()->get();
return view('frontend.pages.berita_detail', array('berita' => $berita,
'beritaRandom' => $beritaRandom ));
我希望输出是 $berita 有一个数组,其中包含与 slug 匹配的字段而不是 null 或空数组
解决方案
$slug = "slug_".App::getLocale();
$berita = Report::select("*", "$title", "$content")->where('slug_'.App::getLocale(), $slug)->first();
您在这里所做的实际上是检查 slug_LOCALE 是否等于自身。因此倾倒时预计会为空$berita
。
祝你好运
推荐阅读
- session - 如何在会话结束时运行查询?
- scala - 使用 Spark Streaming API 测试 Twitter
- excel - VBA Excel:保存到不同的目录
- java - Java 测量
- php - 阻止 PHP 回显特定标签(但仍回显其他标签)
- python - 将 NetCDF (.nc) 转换为 GEOTIFF
- angular - 使用 Angular 查询 Firebase 以获取文档密钥
- php - phpUnit测试elasticsearch结果为空
- ios - React Native 如何使用 expo 和 firebase 设置推送通知
- linux - 对 RHEL 6 使用 PowerCLI Invoke-VMScript 时,ifconfig 和 ping 命令不提供响应,为什么?