Dwight Watson's blog

Don't use View::composer() with wildcard

June 11, 2019

This is incredibily obvious in hindsight, but I recently realised a mistake I had been making when trying to share data across all the views in my app. By wanting to make the count of users in the app

use App\User;

View::composer('*', function () {
    $view->with('usersCount', User::remember(now()->addDay())->count());
});

A blog about Laravel & Rails by Dwight Watson;
developer of Roomies.com, myRent.co.nz & StudentVIP.com.au.

Follow me on Twitter, or GitHub.