I have this bad code (sorry) which using too many of MySQL queries sorry its too long
return view(\'dashboard.homepage\', array(
\'DriversNum
Alright!! Let's do it.
First of all, I highly recommend using barryvdh/laravel-debugbar
(GitHub). This will tell you exactly how many queries were fired and how much time each one took.
Now, let's talk about optimisation.
select()
whenever possible. If a table has 20 columns and about 1000 rows and all your are doing is count() or sum() then fetching all the data doesn't make sense.\App\Models\Drivers
is being used multiple times. Here's what I recommend:
\App\Models\Drivers::where('is_approved', 1)->count();
\App\Models\Drivers::where('is_approved', 0)->count();
$drivers = \App\Models\Drivers::whereIn('is_approved', [0, 1])->get();
$drivers->where('is_approved', 1)->count()
$drivers->where('is_approved', 0)->count()
Indexing
is another solution.
Check out this stack overflow discussion.caching
if you can. (docs)is_approved
column in sql is not an integer then while querying with where(string, int)
will result in load time. It's better to have same data type i.e. where(int, int)
Hope this helps. Cheers!