我想通过 – > with(key,val)函数将信息从一个函数发送到另一个函数,但它不起作用.我尝试了很多东西,但它不起作用.
这是我的实际设置(我正在使用laravel 5.2):
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()传递会话数据,而不是变量.所以你需要使用session get()方法来获取数据:
{{ Session::get('hello') }}
此外,如果您使用的是5.2.27或更高版本,则为remove web
middleware to make sessions work.