<?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?
滿天的星座2017-05-16 16:56:35
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.
PHP中文网2017-05-16 16:56:35
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.