我试图重定向到上一页的消息时,有一个致命的错误。

App::fatal(function($exception)
{
    return Redirect::back()->with('msg', 'The Message');
}

在视图中尝试访问msg

Sessions::get('msg')

但是什么都没有渲染,是我做错了吗?


当前回答

在控制器

例如

return redirect('login')->with('message',$message);

刀片锉 消息将存储在会话中而不是变量中。

例如

@if(session('message'))
{{ session('message') }}
@endif

其他回答

Try

return Redirect::back()->withErrors(['msg' => 'The Message']);

在视图中调用这个

@if($errors->any())
<h4>{{$errors->first()}}</h4>
@endif

在叶片

 @if(Session::has('success'))

    <div class="alert alert-success" id="alert">
        <strong>Success:</strong> {{Session::get('success')}}
    </div>

@elseif(session('error'))
    <div class="alert alert-danger" id="alert">
        
        <strong>Error:</strong>{{Session::get('error')}}
    </div>
@endif

在控制器 成功的

 return redirect()->route('homee')->with('success','Successfully Log in '); 

为错误

 return back()->with('error',"You are not able to access");

# Laravel-9 刀片内部,该重定向返回操作启动的地方

   return redirect()->back()->with('message', "The Message");            

刀片内部的这种形式,将在上述动作后返回

                @if(session()->has('message'))
                <p class="alert alert-success"> {{ session()->get('message') }}</p>
                @endif

在控制器

例如

return redirect('login')->with('message',$message);

刀片锉 消息将存储在会话中而不是变量中。

例如

@if(session('message'))
{{ session('message') }}
@endif

在Laravel 5.5中:

return back()->withErrors($arrayWithErrors);

在使用Blade的视图中:

@if($errors->has())
    <ul>
    @foreach ($errors->all() as $error)
        <li>{{ $error }}</li>
    @endforeach
    </ul>
@endif