Laravel Debugger showing duplicated queries

1.6k Views Asked by At

enter image description here

Does any one has an idea about this. I don't know why it is showing duplicated queries. I searched a lot, found one answer on stackoverflow, but didn't get proper answer. If anyone faced the same error then please let me know. Thank you

protected $_param;
public function __construct(Utility $utility)
{
    $league = $utility->checkDomainController();
    view()->share('league', $league);

    $this->league = $league;
}

This is the code in controller. which shares league to all the views. But there is only one query in $league = $utility->checkDomainController();

Here is the checkDomainController

if(\Request::server('HTTP_HOST') == env('MAIN_DOMAIN'))
    {
        $leagueSlug = Route::current()->getParameter('league');
        $league = League::where('url', $leagueSlug)->first();
    }
    else
    {
        $league = League::where('custom_domain', \Request::server('HTTP_HOST'))->first();
    }
    if(!$league)
    {
      //error page
    }

    return $league;
1

There are 1 best solutions below

0
On

Anytime you call a property which relies on a related model in blade, Laravel executes a new query, unless you eager load and pass from the controller to the view the preloaded data.

This example you posted seems to me as a loop somewhere within your blade code. Maybe if you can share a bit more of the code related to the front-end, I can help you figure it out.