'How can I fix the error from Backpack: view(<alert>) showing error?

I am trying to implement a method in Backpack that will show an alert when a user other than the admin role tries to log in to the admin panel, but I cannot implement the part in checkifadmin()!

private function respondToUnauthorizedRequest($request)
{
    if ($request->ajax() || $request->wantsJson()) {
        return response(trans('backpack::base.unauthorized'), 401);
    } else {
        \Alert::add('success', 'You have successfully logged in')->flash();
        return backpack_view('success');
    }
}

However, when I execute the code, it throws an error.

Attempt to read property "headers" on string



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source