Dwight Watson's blog

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

This blog post was originally published a little while ago. Please consider that it may no longer be relevant or even accurate.

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;

Picture of Dwight Watson

Follow me on Twitter, or GitHub.