这个表达式(终止)用于哪个目的?

时间:2018-05-04 14:04:25

标签: laravel

我终止中间件如下:

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Log;

    class ExampleMiddleware
    {
        /**
         * Handle an incoming request.
         *
         * @param  \Illuminate\Http\Request  $request
         * @param  \Closure  $next
         * @return mixed
         */
        public function handle($request, Closure $next, $role)
        {
            if ($role == null) {
                return redirect('/deneme');
            }
            return $next($request);
        }
        public function terminate($request, $response)
        {
           sleep(4);//what is the purpose in this section(What this means is that anyone who has used this way?)
        }
    }

终止功能的目的是什么,它应该在什么时候使用?

1 个答案:

答案 0 :(得分:1)

  

有时,在准备好HTTP响应后,中间件可能需要做一些工作。例如,&#34;会话&#34; Laravel附带的中间件在响应完全准备好后将会话数据写入存储。如果在中间件上定义终止方法,则在响应准备好发送到浏览器后将自动调用它。

Terminable Middleware