lundi 29 février 2016

Laravel - Provider data being requested on all routes

I am currently using a Laravel Provider to pass data to a view each time it is called. The App.blade.php includes the blade file if the user is authenticated.

My problem is that at the moment, no matter what view the user is on, it still calls the ViewServiceProvider.php, which doesn't seem very efficient.

I have tried to use @if(view()->exists('home')), but that doesn't seem to have any effect what so ever, and thus, the queries are still called from the ViewServiceProvider.php.

App.blade.php:

@if(!Auth::guest())

  @if(view()->exists('home'))

    @include('layouts.check')

  @endif

@endif

ViewServiceProvider.php:

public function boot()
    {
      view()->composer('layouts.check', function ($view) {

        $sites = Site::where('trust_id', Auth::id())->get();

        $view->with(['sites' => $sites]);
      });
    }

Any help would be hugely appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire