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
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

0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.