Laravel 重定向->with(key, val) 不工作
Laravel Redirect->with(key, val) not working
我想使用 ->with(key, val)
函数将信息从一个函数发送到另一个函数,但它不起作用。我已经尝试了很多东西,但它不起作用。
这是我的实际设置 (我使用的是 laravel 5.2):
routes.php
Route::group(['middleware' => ['web']], function() {
Route::get("/test1", "InfoController@test1");
Route::get("/test2", "InfoController@test2");
});
InfoController.php
class InfoController extends Controller
{
public function test1(){
return View::make("infos");
}
public function test2(){
return Redirect::to("/test1")->with("hello", "world");
}
}
Infos.blade.php
{{\Illuminate\Support\Facades\Session::get("hello")}}
坐空->无输出。
问题出在哪里?
with()
传递会话数据,而不是变量。所以需要使用sessionget()
方法获取数据:
{{ Session::get('hello') }}
此外,如果您使用的是 5.2.27 或更高版本,。
问题是web
中间件的使用:
Route::group(['middleware' => ['web']], function() {
默认情况下,此中间件适用于整个应用程序。所以,再次调用它只会破坏闪存和会话数据。
我想使用 ->with(key, val)
函数将信息从一个函数发送到另一个函数,但它不起作用。我已经尝试了很多东西,但它不起作用。
这是我的实际设置 (我使用的是 laravel 5.2):
routes.php
Route::group(['middleware' => ['web']], function() {
Route::get("/test1", "InfoController@test1");
Route::get("/test2", "InfoController@test2");
});
InfoController.php
class InfoController extends Controller
{
public function test1(){
return View::make("infos");
}
public function test2(){
return Redirect::to("/test1")->with("hello", "world");
}
}
Infos.blade.php
{{\Illuminate\Support\Facades\Session::get("hello")}}
坐空->无输出。
问题出在哪里?
with()
传递会话数据,而不是变量。所以需要使用sessionget()
方法获取数据:
{{ Session::get('hello') }}
此外,如果您使用的是 5.2.27 或更高版本,
问题是web
中间件的使用:
Route::group(['middleware' => ['web']], function() {
默认情况下,此中间件适用于整个应用程序。所以,再次调用它只会破坏闪存和会话数据。