Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

spAo's avatar
Level 1

Laravellocalization search in different language

Hello, I'm trying to search in different language. How i read in documentation i must use ' join ' on translations but it don't working.

Every search works except translations.

Controller:

 public function webSearch(Request $request)
    {
        $translations = \DB::table('articles')->join('translations', 'articles.id', '=', 'translations.id')->where('title', 'LIKE', "%{$request->search}%")->orderBy('published_at', 'Desc')->get();
        $articles = Article::where('title', 'LIKE', "%{$request->search}%")->orderBy('published_at', 'Desc')->get();
        $episodes = Episode::where('title', 'LIKE', "%{$request->search}%")->orderBy('published_at', 'Desc')->get();
        $quizzes = Quizze::where('title', 'LIKE', "%{$request->search}%")->orderBy('published_at', 'Desc')->get();
        $shows = Show::where('title', 'LIKE', "%{$request->search}%")->orderBy('published_at', 'Desc')->get();
        return view('pages/search')
            ->with('articles', $articles)
            ->with('episodes', $episodes)
            ->with('quizzes', $quizzes)
            ->with('shows', $shows)
            ->with('translations', $translations);
    }
0 likes
1 reply
Yassen Sayed's avatar

Maybe you like to search in all allowed locales in your system that's correct? If you like to search in all languages you can do that.

Create helper class and fetch all allowed locales & convert it to a single array. In your quires for example $articles = Article::where('title', 'LIKE', "%{$request->search}%")->orderBy('published_at', 'Desc')->whereIn('locale', localesArray())->get(); If you need help I am here to help you.

Please or to participate in this conversation.