skip to Main Content

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?

3

Answers


  1. 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
    
    Login or Signup to reply.
  2. 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') }}
    
    Login or Signup to reply.
  3. When you do:

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

    in your blade view, you should do:

    @dump(session('data') ?? '')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search