首页 > 解决方案 > 中间件干扰会话消息

问题描述

我正在开发一个仪表板,我正在尝试处理错误,为此我在 handler.php 上有这段代码

public function render($request, Throwable $e)
{        

    if($e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException)
    {
        if(Auth::user() && (Auth::user()->isStaff() || Auth::user()->isAdmin()))
        {
            return response()->view('dashboard.404error', [], 404);
        }
        return response()->view('404error', [], 404);
    }
    elseif ($e instanceof \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException) {
        return response()->view('405error', [], 405);
    }
    // elseif($this->isHttpException($e) && $e->getStatusCode() == '405')
    // {
    //     return response()->view('404error', [], 404);
    // }
    return parent::render($request, $e);  
}

但是要检查用户是否登录以及它是什么类型,我必须在 kernel.php 上添加这个中间件:

中间件:

\Illuminate\Session\Middleware\StartSession::class,

但我不知道为什么在那之后我的弹出窗口在我编辑或创建一个员工时停止出现,我不知道为什么。

在此处输入图像描述

通常在视图中,我会用以下内容返回它们:

return redirect()->route('admin.operadoras')
->with('alert-msg', 'Staff edited with success')
->with('alert-type', 'danger');

我对刀片视图的看法是:

@if (session('alert-msg'))
            @include('partials.message')
@endif

我不知道为什么那个中间件会干扰这个消息。

标签: phplaravel

解决方案


推荐阅读