如何只显示一次消息?
How to show message only once?
我有带字段的配置文件表单,使用时应填写。
提交按钮后我重定向到另一个控制器(页面)。
如何只显示一次消息?我的意思是,如果用户再次更新个人资料,消息将不会显示更多。
你的函数:
public function deleteObject($ho_id) {
return redirect()->back()->with('message', 'My message.'); //return back and set a session key, message
}
您的代码(您要扩展的布局)
@if (Session::has('message'))<!-- check if hash message key in session -->
<div class="callout callout-info">
<h4>
Message
</h4>
<p>{{ Session::get('message') }}</p><!-- show the message -->
</div>
@endif
希望这有效!
您只需要使用闪烁的 session 数据进行重定向。例如,
在你的路线文件中,你可能有这个:
Route::post('user/profile', function () {
// Update the user's profile...
return redirect('dashboard')->with('status', 'Profile updated!');
});
在您的 blade 文件中,检查并显示存储在 sessions
中的 'message'
@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif
有关详细信息,请访问 https://laravel.com/docs/5.3/redirects#redirecting-with-flashed-session-data
试试这个,它只会显示一次消息:
if($user_update) {
if(Session::has('update_profile_message') {
return redirect()->back(); //or wherever you want to redirect
} else {
return redirect()->back()->with('update_profile_message', 'Your profile has been updated successfully.');
}
}
我有带字段的配置文件表单,使用时应填写。
提交按钮后我重定向到另一个控制器(页面)。
如何只显示一次消息?我的意思是,如果用户再次更新个人资料,消息将不会显示更多。
你的函数:
public function deleteObject($ho_id) {
return redirect()->back()->with('message', 'My message.'); //return back and set a session key, message
}
您的代码(您要扩展的布局)
@if (Session::has('message'))<!-- check if hash message key in session -->
<div class="callout callout-info">
<h4>
Message
</h4>
<p>{{ Session::get('message') }}</p><!-- show the message -->
</div>
@endif
希望这有效!
您只需要使用闪烁的 session 数据进行重定向。例如, 在你的路线文件中,你可能有这个:
Route::post('user/profile', function () {
// Update the user's profile...
return redirect('dashboard')->with('status', 'Profile updated!');
});
在您的 blade 文件中,检查并显示存储在 sessions
中的 'message'@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif
有关详细信息,请访问 https://laravel.com/docs/5.3/redirects#redirecting-with-flashed-session-data
试试这个,它只会显示一次消息:
if($user_update) {
if(Session::has('update_profile_message') {
return redirect()->back(); //or wherever you want to redirect
} else {
return redirect()->back()->with('update_profile_message', 'Your profile has been updated successfully.');
}
}