(php) laravel在中间件内生成的变量如何传到控制器

在中间件内获取到一个变量,如何返回到控制器中并使用这个变量!

做了个demo:

// web.php
Route::get/check, CheckController@check->middlewareAppHttpMiddlewareCheckRequest::class; // Middleware/CheckRequest.php
class CheckRequest
{ /** * Handle an incoming request. * * @param IlluminateHttpRequest $request * @param Closure $next * @return mixed */ public function handle$request, Closure $next { $check_request = CheckRequest; $request->attributes->addcompactcheck_request; return $next$request; }
} // CheckController.php
//use Request;
use IlluminateHttpRequest;
class CheckController extends Controller
{ public function checkRequest $request { return $request->getcheck_request; // 输出CheckRequest } public function check2 { return Request::getcheck_request; // 输出CheckRequest }
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注