diff --git a/blade.md b/blade.md index 2fcf04373c..f0a3a12183 100644 --- a/blade.md +++ b/blade.md @@ -605,25 +605,25 @@ The following example creates a `@datetime($var)` directive which formats a give class AppServiceProvider extends ServiceProvider { /** - * Register bindings in the container. + * Perform post-registration booting of services. * * @return void */ - public function register() + public function boot() { - // + Blade::directive('datetime', function ($expression) { + return "format('m/d/Y H:i'); ?>"; + }); } /** - * Bootstrap any application services. + * Register bindings in the container. * * @return void */ - public function boot() + public function register() { - Blade::directive('datetime', function ($expression) { - return "format('m/d/Y H:i'); ?>"; - }); + // } } @@ -641,7 +641,7 @@ Programming a custom directive is sometimes more complex than necessary when def use Illuminate\Support\Facades\Blade; /** - * Bootstrap any application services. + * Perform post-registration booting of services. * * @return void */ diff --git a/cache.md b/cache.md index b7407a983d..c360764fd7 100644 --- a/cache.md +++ b/cache.md @@ -379,25 +379,25 @@ To register the custom cache driver with Laravel, we will use the `extend` metho class CacheServiceProvider extends ServiceProvider { /** - * Register bindings in the container. + * Perform post-registration booting of services. * * @return void */ - public function register() + public function boot() { - // + Cache::extend('mongo', function ($app) { + return Cache::repository(new MongoStore); + }); } /** - * Bootstrap any application services. + * Register bindings in the container. * * @return void */ - public function boot() + public function register() { - Cache::extend('mongo', function ($app) { - return Cache::repository(new MongoStore); - }); + // } } diff --git a/database.md b/database.md index ed39c40d63..e02b228151 100644 --- a/database.md +++ b/database.md @@ -167,16 +167,6 @@ If you would like to receive each SQL query executed by your application, you ma class AppServiceProvider extends ServiceProvider { - /** - * Register any application services. - * - * @return void - */ - public function register() - { - // - } - /** * Bootstrap any application services. * @@ -190,6 +180,16 @@ If you would like to receive each SQL query executed by your application, you ma // $query->time }); } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + // + } } diff --git a/eloquent-resources.md b/eloquent-resources.md index d58a8cc142..800bc17366 100644 --- a/eloquent-resources.md +++ b/eloquent-resources.md @@ -324,23 +324,23 @@ If you would like to disable the wrapping of the outer-most resource, you may us class AppServiceProvider extends ServiceProvider { /** - * Register bindings in the container. + * Perform post-registration booting of services. * * @return void */ - public function register() + public function boot() { - // + Resource::withoutWrapping(); } /** - * Bootstrap any application services. + * Register bindings in the container. * * @return void */ - public function boot() + public function register() { - Resource::withoutWrapping(); + // } } diff --git a/eloquent-serialization.md b/eloquent-serialization.md index a6cb92bf42..2d1ea53bb9 100644 --- a/eloquent-serialization.md +++ b/eloquent-serialization.md @@ -187,24 +187,24 @@ Laravel extends the [Carbon](https://github.com/briannesbitt/Carbon) date librar class AppServiceProvider extends ServiceProvider { /** - * Register bindings in the container. + * Perform post-registration booting of services. * * @return void */ - public function register() + public function boot() { - // + Carbon::serializeUsing(function ($carbon) { + return $carbon->format('U'); + }); } /** - * Bootstrap any application services. + * Register bindings in the container. * * @return void */ - public function boot() + public function register() { - Carbon::serializeUsing(function ($carbon) { - return $carbon->format('U'); - }); + // } } diff --git a/eloquent.md b/eloquent.md index 3a12debed3..8f25c61e90 100644 --- a/eloquent.md +++ b/eloquent.md @@ -877,7 +877,7 @@ To register an observer, use the `observe` method on the model you wish to obser class AppServiceProvider extends ServiceProvider { /** - * Register any application services. + * Register the service provider. * * @return void */ diff --git a/filesystem.md b/filesystem.md index 938b130477..16d2065377 100644 --- a/filesystem.md +++ b/filesystem.md @@ -408,17 +408,7 @@ Next, you should create a [service provider](/docs/{{version}}/providers) such a class DropboxServiceProvider extends ServiceProvider { /** - * Register bindings in the container. - * - * @return void - */ - public function register() - { - // - } - - /** - * Bootstrap any application services. + * Perform post-registration booting of services. * * @return void */ @@ -432,6 +422,16 @@ Next, you should create a [service provider](/docs/{{version}}/providers) such a return new Filesystem(new DropboxAdapter($client)); }); } + + /** + * Register bindings in the container. + * + * @return void + */ + public function register() + { + // + } } The first argument of the `extend` method is the name of the driver and the second is a Closure that receives the `$app` and `$config` variables. The resolver Closure must return an instance of `League\Flysystem\Filesystem`. The `$config` variable contains the values defined in `config/filesystems.php` for the specified disk. diff --git a/packages.md b/packages.md index 4e16e7ef03..41a1b13d14 100644 --- a/packages.md +++ b/packages.md @@ -84,7 +84,7 @@ A service provider extends the `Illuminate\Support\ServiceProvider` class and co Typically, you will need to publish your package's configuration file to the application's own `config` directory. This will allow users of your package to easily override your default configuration options. To allow your configuration files to be published, call the `publishes` method from the `boot` method of your service provider: /** - * Bootstrap any application services. + * Perform post-registration booting of services. * * @return void */ @@ -125,7 +125,7 @@ You may also merge your own package configuration file with the application's pu If your package contains routes, you may load them using the `loadRoutesFrom` method. This method will automatically determine if the application's routes are cached and will not load your routes file if the routes have already been cached: /** - * Bootstrap any application services. + * Perform post-registration booting of services. * * @return void */ @@ -140,7 +140,7 @@ If your package contains routes, you may load them using the `loadRoutesFrom` me If your package contains [database migrations](/docs/{{version}}/migrations), you may use the `loadMigrationsFrom` method to inform Laravel how to load them. The `loadMigrationsFrom` method accepts the path to your package's migrations as its only argument: /** - * Bootstrap any application services. + * Perform post-registration booting of services. * * @return void */ @@ -157,7 +157,7 @@ Once your package's migrations have been registered, they will automatically be If your package contains [translation files](/docs/{{version}}/localization), you may use the `loadTranslationsFrom` method to inform Laravel how to load them. For example, if your package is named `courier`, you should add the following to your service provider's `boot` method: /** - * Bootstrap any application services. + * Perform post-registration booting of services. * * @return void */ @@ -175,7 +175,7 @@ Package translations are referenced using the `package::file.line` syntax conven If you would like to publish your package's translations to the application's `resources/lang/vendor` directory, you may use the service provider's `publishes` method. The `publishes` method accepts an array of package paths and their desired publish locations. For example, to publish the translation files for the `courier` package, you may do the following: /** - * Bootstrap any application services. + * Perform post-registration booting of services. * * @return void */ @@ -196,7 +196,7 @@ Now, when users of your package execute Laravel's `vendor:publish` Artisan comma To register your package's [views](/docs/{{version}}/views) with Laravel, you need to tell Laravel where the views are located. You may do this using the service provider's `loadViewsFrom` method. The `loadViewsFrom` method accepts two arguments: the path to your view templates and your package's name. For example, if your package's name is `courier`, you would add the following to your service provider's `boot` method: /** - * Bootstrap any application services. + * Perform post-registration booting of services. * * @return void */ @@ -220,7 +220,7 @@ When you use the `loadViewsFrom` method, Laravel actually registers two location If you would like to make your views available for publishing to the application's `resources/views/vendor` directory, you may use the service provider's `publishes` method. The `publishes` method accepts an array of package view paths and their desired publish locations: /** - * Bootstrap any application services. + * Perform post-registration booting of services. * * @return void */ @@ -261,7 +261,7 @@ To register your package's Artisan commands with Laravel, you may use the `comma Your package may have assets such as JavaScript, CSS, and images. To publish these assets to the application's `public` directory, use the service provider's `publishes` method. In this example, we will also add a `public` asset group tag, which may be used to publish groups of related assets: /** - * Bootstrap any application services. + * Perform post-registration booting of services. * * @return void */ @@ -282,7 +282,7 @@ Now, when your package's users execute the `vendor:publish` command, your assets You may want to publish groups of package assets and resources separately. For instance, you might want to allow your users to publish your package's configuration files without being forced to publish your package's assets. You may do this by "tagging" them when calling the `publishes` method from a package's service provider. For example, let's use tags to define two publish groups in the `boot` method of a package service provider: /** - * Bootstrap any application services. + * Perform post-registration booting of services. * * @return void */ diff --git a/providers.md b/providers.md index 0b6c9857c8..78339f7d6c 100644 --- a/providers.md +++ b/providers.md @@ -165,7 +165,7 @@ To defer the loading of a provider, implement the `\Illuminate\Contracts\Support class RiakServiceProvider extends ServiceProvider implements DeferrableProvider { /** - * Register any application services. + * Register the service provider. * * @return void */ diff --git a/queues.md b/queues.md index b4c9d3d1be..6344c64886 100644 --- a/queues.md +++ b/queues.md @@ -690,7 +690,7 @@ If you would like to register an event that will be called when a job fails, you class AppServiceProvider extends ServiceProvider { /** - * Register any application services. + * Register the service provider. * * @return void */ @@ -767,16 +767,6 @@ Using the `before` and `after` methods on the `Queue` [facade](/docs/{{version}} class AppServiceProvider extends ServiceProvider { - /** - * Register any application services. - * - * @return void - */ - public function register() - { - // - } - /** * Bootstrap any application services. * @@ -796,6 +786,16 @@ Using the `before` and `after` methods on the `Queue` [facade](/docs/{{version}} // $event->job->payload() }); } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + // + } } Using the `looping` method on the `Queue` [facade](/docs/{{version}}/facades), you may specify callbacks that execute before the worker attempts to fetch a job from a queue. For example, you might register a Closure to rollback any transactions that were left open by a previously failed job: diff --git a/session.md b/session.md index 275dcf4b08..df0753aa57 100644 --- a/session.md +++ b/session.md @@ -247,26 +247,26 @@ Once your driver has been implemented, you are ready to register it with the fra class SessionServiceProvider extends ServiceProvider { /** - * Register bindings in the container. + * Perform post-registration booting of services. * * @return void */ - public function register() + public function boot() { - // + Session::extend('mongo', function ($app) { + // Return implementation of SessionHandlerInterface... + return new MongoSessionHandler; + }); } /** - * Bootstrap any application services. + * Register bindings in the container. * * @return void */ - public function boot() + public function register() { - Session::extend('mongo', function ($app) { - // Return implementation of SessionHandlerInterface... - return new MongoSessionHandler; - }); + // } } diff --git a/validation.md b/validation.md index 2bdd5be466..cf13dd32ef 100644 --- a/validation.md +++ b/validation.md @@ -1236,25 +1236,25 @@ Another method of registering custom validation rules is using the `extend` meth class AppServiceProvider extends ServiceProvider { /** - * Register any application services. + * Bootstrap any application services. * * @return void */ - public function register() + public function boot() { - // + Validator::extend('foo', function ($attribute, $value, $parameters, $validator) { + return $value == 'foo'; + }); } /** - * Bootstrap any application services. + * Register the service provider. * * @return void */ - public function boot() + public function register() { - Validator::extend('foo', function ($attribute, $value, $parameters, $validator) { - return $value == 'foo'; - }); + // } } diff --git a/views.md b/views.md index 5f8dd1bbae..59614aedf5 100644 --- a/views.md +++ b/views.md @@ -79,23 +79,23 @@ Occasionally, you may need to share a piece of data with all views that are rend class AppServiceProvider extends ServiceProvider { /** - * Register any application services. + * Bootstrap any application services. * * @return void */ - public function register() + public function boot() { - // + View::share('key', 'value'); } /** - * Bootstrap any application services. + * Register the service provider. * * @return void */ - public function boot() + public function register() { - View::share('key', 'value'); + // } } @@ -116,17 +116,7 @@ For this example, let's register the view composers within a [service provider]( class ViewServiceProvider extends ServiceProvider { /** - * Register any application services. - * - * @return void - */ - public function register() - { - // - } - - /** - * Bootstrap any application services. + * Register bindings in the container. * * @return void */ @@ -142,6 +132,16 @@ For this example, let's register the view composers within a [service provider]( // }); } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + // + } } > {note} Remember, if you create a new service provider to contain your view composer registrations, you will need to add the service provider to the `providers` array in the `config/app.php` configuration file.