View composer making phpunit tests and page slow
I have found that by simply having a view()->composer() in my service provider it dramatically slows down my phpunit test suite and somewhat slows down my page loads even on pages that the view composer is not being used on.
If I comment out the composer lines, the unit tests go quickly. I have even tried the most basic of composers just make sure it's not the view file or the contents of the callback that is slowing it down and yes the 'test' view does exist.
view()->composer('test', function(){});
I have tried switching the order of the service providers, moving the composer code to a different provider and nothing makes it better other than literally removing/commenting out the composer lines. I'm at a loss. I have the same concept stuff in another app with no issues. Google has gotten me nowhere.
I need your suggestions!
<?php
namespace App\Providers;
use App\Helpers\Cart\Facades\Cart;
use App\Models\Products\Category;
use Illuminate\Support\ServiceProvider;
/**
* Class ViewComposerProvider
* @package App\Providers
*/
class ViewComposerProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
view()->composer('layouts.partials.cart.cart-link', function($view){
$view->with('cart_count', Cart::count());
});
view()->composer('layouts.partials.category-dropdown', function($view){
$view->with('categories_menu', Category::notPrivatized()->get());
});
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
Please or to participate in this conversation.