The use of Laravel middleware

Source: Internet
Author: User

1. Save directory between parts: App/http/middleware


2. Custom middleware:

(1) PHP artisan make:middleware [namemiddleware]//Generate in-between class templates

(2) in the App/http/middleware class in open creation, the handle method implements its own logic. //parameter one is the request, parameter two is the next middleware, can add other required parameters to parameter two.

(3) After writing its processing logic on the return $next ($request), it indicates that the middleware executes after the request, and vice versa after the request.

(4) Register middleware (make Effective): in the Routemiddleware array of the file app\http\kernel.php, add its own key value between the pieces.

(5) The second parameter in the route specifies the middleware to be used, [' middleware ' = ' + ' Middleware 1: parameters, middleware two ... ']


The use of Laravel middleware

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.