kwestionable
kwestionable

Reputation: 496

Redirect to another route with data Laravel 5.8

Good day everyone. I am encountering an error in my code. I am trying to redirect to another route and passing data with it.

Controller code:

    return redirect()->route('customer.success', compact('data'));

Route:

    Route::get('success-customer', 'CustomerController@showSuccess')->name('customer.success');

Blade:

    Your assistant: {{Session::get($data['assistant'])}}

Now my error is, it shows the error of undefined data yet I used the compact function. Answers and advices are highly appreciated!

Upvotes: 1

Views: 3463

Answers (3)

user10678889
user10678889

Reputation:

You can use this:

return redirect()->route('profile', ['id' => 1]);

To redirect to any controller, use this code

return redirect()->action('DefaultController@index');

If you want to send data using redirect, try to use this code

return Redirect::route('customer.success)->with( ['data' => $data] );

To read the data in blade, use this one

// in PHP
$id = session()->get( 'data' );

// in Blade
{{ session()->get( 'data' ) }}

Check here for more info

Upvotes: 1

Madhuri Patel
Madhuri Patel

Reputation: 1270

In laravel 5.8 you can do the following:

return redirect('login')->with('data',$data);

in blade file The data will store in session not in variable.

{{ Session::get('data') }}

Upvotes: 2

albus_severus
albus_severus

Reputation: 3702

TRy this

  return Redirect::route('customer.success')->with(['data'=>$data]); 

In blade

Session::get('data');

Upvotes: 0

Related Questions