我正在學習Laravel。我試圖創建一個表單,列出汽車表中的汽車,如果點擊,發送到另一個基於數據庫查詢的表單,該表單返回所選汽車的數據(由$ modelesc標識)。在Laravel中獲取MethodNotAllowedHttpException錯誤
該表格將數據發送到「訂單」表。使用我現在的代碼,我無法在訂單表上發佈訂單。它得到的信息: 「MethodNotAllowedHttpException在RouteCollection.php線233:」
這是代碼
Web.php
Route::get('catalog', '[email protected]');
Route::get('orders/', '[email protected]')->name('orders');
CarController
function catalog() {
$cars = DB::table('cars')->get();
return view('catalog', compact('cars'));
}
function orders(Request $request) {
$modelesc = $request->modelesc;
$cars = DB::table('cars')->where('Model', $modelesc)->get();
$colours = DB::table('colours')->get()->pluck('Colour');
return view('orders', compact('cars', 'colours'));
}
Catalog.blade.php
@foreach($cars as $car)
{!! Form::open(array('action' => '[email protected]', 'method' => 'GET')) !!}
{!! Form::hidden('$modelesc', $car->Model) !!}
{!! Form::submit($car->Model) !!}
{!! Form::close() !!}
@endforeach
Orders.blade.php
@foreach($cars as $car)
{!! Form::open(['method' => 'POST']) !!}
<a href="{{route('orders', $car->Model) }}">{{ $car->Model }}</a>
{!! Form::hidden('users_id', Auth::user()->id) !!}
{!! Form::hidden('Fabrication_date', date('Y-m-d')) !!}
{!! Form::select('Colour_id', $colours) !!}
{!! Form::hidden('Order_status_id', '1') !!}
{!! Form::submit('Ok') !!}
{!! Form::close() !!}
@endforeach
的訂單表具有以下結構:
$table->increments('id');
$table->integer('users_id')->unsigned();
$table->foreign('users_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
$table->string('Model');
$table->date('Fabrication_date');
$table->integer('Colour_id')->unsigned();
$table->foreign('Colour_id')->references('id')->on('colours')->onDelete('cascade')->onUpdate('cascade');
$table->integer('Order_status_id')->unsigned();
$table->foreign('Order_status_id')->references('id')->on('order_status')->onDelete('cascade')->onUpdate('cascade');
$table->timestamps();
我已經使用了一些建議,並設法使訂單工作。路線變化無效。但現在我有另一個問題。檢查已編輯的第一篇文章。 – Adato
如果你想爲'post'添加一個新的路由'Route :: post('orders','CarController @ functionName') - > name('orders');'定義一個函數來處理這個。 – EddyTheDove
你說我的答案幫助你解決主要問題。現在你正在解決一個不同的問題。如果是這樣,請好好標記我的答案。謝謝:) – EddyTheDove