重定向到另一个路由时传递参数

Passing parameter while redirecting to another route

我正在尝试 'redirect to' 通过路由从一种控制器方法到另一种控制器方法。但是,我也想传递一些数据。我试过 Session::get('name') 但似乎没有用。这是我试过的:

public function before() {
   return Redirect::to('later')->with('x', 'y');
}

public function later() {
   dd( Session::get('x') ); // null
   dd( $x ) // not working
}

我的路线很经典:

Route::get('/later', 'TheController@later')->middleware('auth');

我错过了什么?

而不是 Session::get('x') 尝试使用 session('x') 因为 below.You 可以使用 if (session()->has('x'))

检查它
public function later() {
   dd( session('x'));
}