Home>

For redirect ()->route ('index') etc. in laravel
I don't know how to pass multiple values ​​when redirecting to a different route.
As a result of checking the log, the status code was 405 when redirecting to the target page.
How to display multiple values ​​given together at the time of redirect at the redirect destination
Please tell me if you know.

Tryed source code
return redirect ()->route ('index')->with ('item', $item->name)->with ('price', $item- >price);
Redirect destination description
Product name: {{session ('item')}}
Amount: {{session ('price')}}
  • Answer # 1

    I wonder if this can be done

    Controller side
    // Abbreviation
        public function destroy ($id)
        {
            $user = User :: find ($id);
            // processing
            if ($user->delete ()) {
                return redirect ('/ top')->with ('message', 'Deleted');
            }
            return redirect ('/ top')->with ('message', 'error');
        }
    View side
    @if (Session :: has ('message'))
        

    {{session ('message')}}

    @endif

    I wonder if there are other references below
    [Laravel] Route (), view () and redirect () frequently used in Laravel-Qiita


    If the value passed is an array,

    @if (Session :: has ('message'))
        

    {{session ('message') [0]}}

        

    {{session ('message') ['item']}}

    @endif

    I didn't do it

  • Answer # 2

    https://laravel.com/api/5.8/Illuminate/Http/RedirectResponse.html#method_with

    It seems to be able to respond by passing an array as a parameter of
    Please check the link once

Related articles