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

P81CFM's avatar

Create a view which contains the multiple data coming from several different mySql tables

Hi guys, I've been following several courses here on Laracasts and the time to start a real project has come. And with this project, arrived also the first massive question.

I have a mySQL db with multiple tables and in a page of the control panel I would like to have a view which will contain the result of multiple queries (not related to each other). Each query will retrieve the number of records in one specific table or similar type of information.

I come from a traditional PHP development and that was pretty easy, it seems that we Laracast this can be even more easy but only after the first attempts.

I'm not looking for code just to have some direction in order to follow the best possible path.

Thanks a lot

0 likes
3 replies
shez1983's avatar
shez1983
Best Answer
Level 23

you have four unrelated queries.. in your controller make those four queries, save in 4 variables (or array) and pass them through blade...

P81CFM's avatar

I follow your advice and I manage to retrieve the variables in the view and print them to the screen

so in the controller I have the following function public function index() { $tot_languages = Language::count(); $tot_countries = Country::count();

    return view('admin.index', compact('tot_languages', 'tot_countries'));
}

and in the view I retrieve the variables

now here is a question more related to the quality of the code what if I have 10 or more variables? What would be the best option?

biishmar's avatar

@P81CFM

if your 10 or more variable is mandatory, of course u have to send it... if its related try using relationship send with less count of variables..

if your variable r not array.. then create those inside array and send it, then it will be less variable

Please or to participate in this conversation.