PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 10, 2022

[FIXED] Laravel route destroy return back issue

 January 10, 2022     laravel, php     No comments   

Issue

I have a step2 form which will store Order first in step1 then go to step2 page which the purpose is storing Aircon

When Click "trash icon" should go to route destroy but after return back() Error: The GET method is not supported for this route. Supported methods: POST.

How to do correctly? passing $order in destroy ?

public function destroy(Aircon $aircon)
{
    $aircon->delete();
    return back();
}
public function store(Request $request, Order $order)
{
    $order = Order::find($order->id);

    $attributes = $this->validateAirCon();

    $order->aircons()->create($attributes);

    return view('pages.user.order-aircons.addAircon',compact('order'));
}
<form action="{{ route('aircon.store', $order) }}" method="post">
    @csrf

    {{--inputs... --}}
    
    <button type="submit">aircon.store</button>
</form>

@forelse ($order->aircons as $aircon)
    <table class="table">
        <th>Model Number</th>
            {{-- th.. --}}
        <tr>
            {{-- td... --}}
            <td>
                {{-- Delete Aircon --}}
                <form action="{{ route('aircon.destroy', $aircon) }}" method="post">
                    @method('DELETE')
                    @csrf
                    {{-- button submit --}}
                </form>
            </td>
        </tr>
    </table>
@empty
    <h1>no data</h1>
@endforelse

enter image description here


Solution

Use the route name:

public function destroy(Aircon $aircon)
{
    $aircon->delete();

    // Put the route name that you want to be redirected to that.
    return redirect()->route('YOUR_ROUTE_NAME');
}


Answered By - mohammadmahdi baleghsefat
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing