Q: cannot pass multiple variables to view laravel I have a problem : I'm currently working on aproject of a web app for a library (it's for school).
And I want to return my view with 3 variables form queries, but it doesn't seem to work. It works for the 2 first but not for the 3rd.
here is my code :
$search_text = $_GET['query'];
            $results = DB::table('clients')->where('id','=',$search_text)->paginate(3); 
            $resultsloan = DB::table('emprunts')->where('clientid', '=', $search_text)->paginate(3);

            // compte le nombre de prets au client, si le nombre est supérieur à 4, le btn pour selectionner le client disparait et un msg d'avertissement apparait (dans formloan)
           $limitemprunts = Emprunt::WhereIn('clientid',[$search_text])->where('clientid',$search_text)->distinct()->get()->count();
            
            return view('crud.formloan', ['results'=>$results],['limitemprunts'=>$limitemprunts],['resultsloan'=>$resultsloan]);

But the $resultsloan seems to never get to my view ...
can someone please help me ?

A: You're passing it wrong to view. You've to use it something like this:
return view('foo',compact('key'=>'bazz','key'=>'bar','key'=>'foo bar'));
or you can do it something like this:
return view('foo',['key'=>'bazz', 'key'=>'bar', 'key'=>'foo bar']);

A: To expand on @Hasssaans's anwer, there are a few ways to pass variable to a view. This can depend on your coding style and also the amount you want to pass.
Another example I use:
return view('foo')->with(['key' => $value, 'users' => $users]);


A: Change your return view as:
return view('crud.formloan', compact('results', 'limitemprunts', 'resultsloan'));

