senty
senty

Reputation: 12857

Passing parameter while redirecting to another route

I am trying to 'redirect to' from one controller method to another through the route. However, I want to pass some data as well. I tried Session::get('name') but doesn't seem to work. This is what I tried:

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

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

My route is like classic:

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

What am I missing?

Upvotes: 0

Views: 78

Answers (1)

TIGER
TIGER

Reputation: 2905

Instead of Session::get('x') try with session('x') as below.You can check for it using if (session()->has('x'))

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

Upvotes: 1

Related Questions