laravel - How to understand Closure $next when defining middleware
迷茫
迷茫 2017-05-16 16:54:35
0
2
648
<?php
    namespace App\Http\Middleware;
    use Closure;
    class TestMiddleware
    {      

        public function handle($request, Closure $next)
            if($request->input('age')<18)
                return redirect()->route('refuse');
            return $next($request);
        }
    }

In the above code,
1) The closure in use Closure in the third line is a class? how come?
2) What does Closure $next mean in the handle method on line 6?
3) $next($request) on line 9, what is the usage? Is $next a function or a variable?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
滿天的星座

Closure is a class that comes with PHP to represent anonymous functions! ! Go to the PHP manual and you will understand the questions you asked.

Ty80

Closure is a class used by PHP to implement closures (anonymous functions).
http://php.net/manual/zh/class.closure.php
$next is the bound function.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!