gpt4 book ai didi

php - MiddleWare 上的 Laravel 返回 View

转载 作者:行者123 更新时间:2023-12-01 15:43:22 25 4
gpt4 key购买 nike

在 Laravel 中,我试图检查用户 active列,如果它是 0那么必须将简单 View 显示为 your account is disable ,在执行以下代码后,我收到此错误:

Call to a member function setCookie() on null

我的中间件:

class CheckUserActive
{
public function handle($request, Closure $next)
{
if (auth()->check()) {
if (auth()->user()->active == 0) {
auth()->logout();
$message = 'your account is disable';
return view('layouts.frontend.pages.user-messages', compact('message'));
}
}
return $next($request);
}
}
kernel.php :
...
protected $middlewareGroups = [
'web' => [
...
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\CheckUserActive::class,

],

'api' => [
'throttle:60,1',
'bindings',
],
];
...
user-messages.blade.php :
@extends('layouts.frontend.main')

@section('content')
<div class="content-wrapper">
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-body">
<p style="text-align: center;">
{!! $message !!}
</p>
</div>
</div>
</div>
</div>
</div>

</div>
@endsection

最佳答案

根据文档,您可以使用访问 View response()->view('custom');

关于php - MiddleWare 上的 Laravel 返回 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50408698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com