First we need to create a service class, for example, called Cqhserviceprovider, the simplest way is to use artisan to help us create
PHP Artisan Make:provider Cqhserviceprovider
We will then see the App\provider folder under which the following file cqhserviceprovider.php is generated, as follows
<?php namespace App\providers;use illuminate\support\serviceprovider;class Cqhserviceprovider extends serviceprovider {/** * Bootstrap the application services. * @return void */public function boot () {//}/** * Register the Application services. * * @return void */public function Register () {//}}
However, this is not available, we need to add this service to our configuration file, open config/app.php, find the providers array, add the service just generated
<?phpreturn [.../* * Application Service Providers ... */' app\providers\appserviceprovider ', ' app\providers\ Busserviceprovider ', ' app\providers\configserviceprovider ', ' app\providers\eventserviceprovider ', ' App\Providers\ Routeserviceprovider ',//Join the service just registered Cqhserviceprovider ' App\providers\cqhserviceprovider ',...],];
So the service will run automatically. We cut it off in Cqhserviceprovider's boot method,
Public Function boot () {exit (' The provider of Cqh ');}
Then, when we open any action, we can see
This is the provider of CQH
The rep service is working!
Laravel 5 registration and use of services