Search code examples
phplaravelmultilinguallaravel-5.7

Laravel Eloquent where return null


I have multilang site with laravel. I'm passing slug for params. Passing from berita to beritaDetail. But it show error and when dd($berita), just show 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 ));

I expect the output is $berita has an array that contain field that match with the slug not null or empty array


Solution

  • $slug = "slug_".App::getLocale();
    
    $berita = Report::select("*", "$title", "$content")->where('slug_'.App::getLocale(), $slug)->first();
    

    what you doing here is actually checking if slug_LOCALE equals to itself. so it is expected to get null when dumping $berita.

    good luck