我了解如何使用redirect()方法重定向用户,但此方法返回302代码,浏览器必须发出第二个HTTP请求。是否可以在内部将请求转发到不同的控制器和操作?
我正在中间件中进行此检查,因此我的句柄函数如下所示:
public function handle($request, Closure $next)
{
if (auth()->user->age <= 20) { //example
//internally forward the user to a different controller@action
}
return $next($request);
}
}
您可以使用call
方法为:
app()->call('App\Http\Controllers\ControllerName@funName')
Or
app('App\Http\Controllers\ControllerName')->funName();
所以你的中间件将如下所示:
if (auth()->user->age <= 20) {
return app()->call('App\Http\Controllers\ControllerName@action');
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)