devsead
devsead

Reputation: 343

Data from controller does not get passed to the view in laravel

I am trying to provide some hardcoded data (for the testing purposes only) from my controller like this

return redirect()->route('admin.my-view.edit', $prop)->withToastSuccess('Success')->with(['data' => ['test1', 'test2']]);

And in my edit page I am trying to dump data like this

@dump($data ?? '')

The issue is that I initially get '' as well as after the redirect.

Am I missing something here?

Upvotes: -1

Views: 60

Answers (4)

devsead
devsead

Reputation: 343

I have solved this issue using cache. I make cache which gets removed after 10 seconds (just in case reload takes more time) and that is it.

Upvotes: -1

Jeyhun Rashidov
Jeyhun Rashidov

Reputation: 1138

When you do:

->with(['data' => ['test1', 'test2']])

in your blade view, you should do:

@dump(session('data') ?? '')

Upvotes: 1

francisco
francisco

Reputation: 2140

Try to use the Redirecting With Flashed Session Data by:

$test = ['test1', 'test2'];
return redirect()->route('admin.my-view.edit', $prop)->withToastSuccess('Success')->with(['data' => $test]);

then on blade:

{{ session('data') }}

Upvotes: 1

Othmane Nemli
Othmane Nemli

Reputation: 1193

You are using with() function which is a flashed session function and you have to get the the data value like that:

@if (session('data'))
    // ...
@endif

// OR
session('data', '') // default value when no data session is passed

Upvotes: 2

Related Questions