Laravel boots
Request comes in to the server, and is handled by Laravel.
Laravel will spin through all service provider classes and run each one’s register
method. You should put any container bindings in here.
public function register(){ $this->app->bind(SomeInterface::class, function () { return new SomeClass; })}
It’ll then loop through them again, this time calling the boot
method. Here’s where you can run any bootstrapping logic.
public function boot(){ //}
Auth service provider boots
As part of the boot process, Statamic will set up its permissions. If you’d like to do anything permission or auth related, (like adding custom permissions) you should wrap your provider code in a booted callback to ensure it happens after Statamic has done its thing.
public function boot(){ $this->app->booted(function () { Permission::register(...); });}
View loads
If you’re using any JavaScript in the Control Panel, you can pass configuration variables to it. You can do this in a service provider or a view composer.
View::composer('statamic::layout', function ($view) { Statamic::provideToScript(['foo' => 'bar']);});
Statamic.$config.get('foo'); // 'bar'
Vue boots
If you’ve ever built a Vue application, you’ll know that any global components need to be registered before the root Vue instance is created. Statamic provides a booting
callback for that.
Statamic.booting(() => { Statamic.$components.register(...);})
Then, the Vue app will boot and you’ll have a chance to do other JavaScript work within a booted
callback. This is almost equivalent to putting things in a created
hook of a Vue component.
This is where you’d do things like adding Bard extensions and wiring up Hooks or events.
Statamic.booted(() => { Statamic.$bard.extend(...); Statamic.$hooks.on(...);});
The Vue part of the lifecycle only applies to Control Panel requests. Since you have 100% control over the front-end of your site, you can do whatever you want there.