Laravel 5 registration and use of services

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.