我有一個 step2 表單,它將Order首先存盤在 step1 中,然后轉到目的是存盤的 step2 頁面Aircon
當點擊“垃圾箱圖示”應該去路由銷毀但return back()
錯誤后:The GET method is not supported for this route. Supported methods: POST.
怎么做才正確?傳入$order破壞?
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

uj5u.com熱心網友回復:
使用路由名稱:
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');
}
uj5u.com熱心網友回復:
問題解決了
使用自定義路由傳遞兩個引數Aircon和Order
Route::delete('/aircon/delete/{aircon}/order{order}', [AirConController::class, 'delete'])->name('aircon.destroy');
public function delete(Aircon $aircon, Order $order)
{
$aircon->delete();
return view('pages.user.order-aircons.addAircon', compact('order'));
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/392929.html
上一篇:我似乎在上傳圖片時遇到問題。我不斷收到“無法將App\Http\Controllers\PostsController型別的物件用作陣列。”
下一篇:Foreach課程部分和課程
