我想使用 ->with(key, val)
函数将信息从一个函数发送到另一个函数,但它不起作用。我已经尝试了很多东西,但都不起作用。
这是我的实际设置(我使用的是 laravel 5.2):
路由.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");
}
}
信息.blade.php
{{\Illuminate\Support\Facades\Session::get("hello")}}
坐空->无输出。
问题出在哪里?
最佳答案
with()
传递 session 数据,而不是变量。所以需要使用session的get()
方法来获取数据:
{{ Session::get('hello') }}
此外,如果您使用的是 5.2.27 或更高版本,remove web
middleware to make sessions work .
关于php - Laravel Redirect->with(key, val) 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39531373/