我试图重定向到上一页的消息时,有一个致命的错误。
App::fatal(function($exception)
{
return Redirect::back()->with('msg', 'The Message');
}
在视图中尝试访问msg
Sessions::get('msg')
但是什么都没有渲染,是我做错了吗?
我试图重定向到上一页的消息时,有一个致命的错误。
App::fatal(function($exception)
{
return Redirect::back()->with('msg', 'The Message');
}
在视图中尝试访问msg
Sessions::get('msg')
但是什么都没有渲染,是我做错了吗?
当前回答
在laravel 5.8中,你可以做以下事情:
return redirect()->back()->withErrors(['name' => 'The name is required']);
在刀刃上:
@error('name')
<p>{{ $message }}</p>
@enderror
其他回答
在Laravel 5.5中:
return back()->withErrors($arrayWithErrors);
在使用Blade的视图中:
@if($errors->has())
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
@endif
在laravel 5.8中,你可以做以下事情:
return redirect()->back()->withErrors(['name' => 'The name is required']);
在刀刃上:
@error('name')
<p>{{ $message }}</p>
@enderror
**Try This**
Try This Code
--- Controller ---
return redirect('list')->with('message', 'Successfully');
return redirect('list');
---- Blade view ------
@if(session()->has('message'))
<div class="alert alert-success">
{{ session()->get('message') }}
</div>
@endif
拉拉维尔 8
Route::post('/user/profile', function () {
// Update the user's profile...
return redirect('/dashboard')->with('status', 'Profile updated!');
});
叶片的语法
@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif
在这里输入链接描述
对于拉拉维尔 5.5+
控制器:
return redirect()->back()->with('success', 'your message here');
叶:
@if (Session::has('success'))
<div class="alert alert-success">
<ul>
<li>{{ Session::get('success') }}</li>
</ul>
</div>
@endif