Laravel 5.2 redirect back with success message(Laravel 5.2 重定向成功消息)
问题描述
我正在尝试将成功消息返回到我的 laravel 主页.
return redirect()->back()->withSuccess('IT WORKS!');由于某种原因,运行此代码后变量 $success 没有得到任何值.
我用来显示成功消息的代码:
@if (!empty($success))<h1>{{$success}}</h1>@万一我已将主页和时事通讯页面添加到 routes.php 中的 Web 中间件组,如下所示:
Route::group(['middleware' => 'web'], function () {路线::认证();路由::get('/', function () {返回视图('家');});Route::post('/newsletter/subscribe','NewsletterController@subscribe');});有人知道为什么这似乎不起作用吗?
您应该从 routes.php 中删除 web 中间件.手动添加 web 中间件会导致 会话和在 Laravel 5.2.27 及更高版本中请求相关问题.
如果它没有帮助(仍然,保持 routes.php 没有网络中间件),你可以尝试一些不同的方法:
return redirect()->back()->with('message', 'IT WORKS!');如果存在则显示消息:
@if(session()->has('message'))<div class="alert alert-success">{{ session()->get('message') }}@万一
I'm trying to get a success message back to my home page on laravel.
return redirect()->back()->withSuccess('IT WORKS!');
For some reason the variable $success doesn't get any value after running this code.
The code I'm using to display the succes message:
@if (!empty($success))
<h1>{{$success}}</h1>
@endif
I have added the home and newsletter page to the web middleware group in routes.php like this:
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/', function () {
return view('home');
});
Route::post('/newsletter/subscribe','NewsletterController@subscribe');
});
Does anyone have any idea why this doesn't seem to work?
You should remove web middleware from routes.php. Adding web middleware manually causes session and request related problems in Laravel 5.2.27 and higher.
If it didn't help (still, keep routes.php without web middleware), you can try little bit different approach:
return redirect()->back()->with('message', 'IT WORKS!');
Displaying message if it exists:
@if(session()->has('message'))
<div class="alert alert-success">
{{ session()->get('message') }}
</div>
@endif
这篇关于Laravel 5.2 重定向成功消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Laravel 5.2 重定向成功消息
基础教程推荐
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
