Support the ongoing development of Laravel.io →
posted 9 years ago
Views
Last updated 2 years ago.
0

At the very end of Views section of docs there's a mention of creators, maybe they will work as you want:

View creators work almost exactly like view composers; however, they are fired immediately when the view is instantiated. To register a view creator, use the creator method:

View::creator('profile', 'App\Http\ViewCreators\ProfileCreator');

0

Spot on, thanks Xum!

Looking at the source code, the two functions set up events, 'creating:' and 'composing:'

$composers[] = $this->addViewEvent($view, $callback, 'composing: ', $priority);

I guess this code is run as part of the view lifecycle.

It's a shame the naming is not particularly intuitive - creator() sounds like it would do something completely different, such as create a view. This is strange, as I know one of Tylor Otwell's aims is to provide readable / obvious method names.

It seems to be this would be more consistently implemented (as per controller filters) as View::beforeFilter() and View::afterFilter() rather than View::create() and View::compose().

Anyway, thanks for the pointer.

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.