Laravel을 배우고 있습니다. 자동차 테이블에있는 자동차를 나열하는 양식을 만들려고합니다. 클릭하면 선택한 모델 ($ modelesc로 식별)의 데이터를 반환하는 DB 쿼리를 기반으로 다른 양식으로 보냅니다.Lolavel에서 MethodNotAllowedHttpException 오류가 발생했습니다.
이 양식은 데이터를 "주문"테이블로 보냅니다. 지금 가지고있는 코드를 사용하면 주문 테이블에 주문을 게시 할 수 없습니다. "RouteCollection.php 라인 (233)에 MethodNotAllowedHttpException :"
이 코드
이 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
,210
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
'Route :: post ('orders', 'CarController @ functionName') -> name ('orders'); 게시물을위한 새 경로를 추가하려면 'POST'를하고 그 일을 처리 할 함수를 정의하십시오 . – EddyTheDove
당신은 내 대답이 당신이 주요 질문을하는 데 도움이된다고 말했다. 이제 다른 질문을 해결하고 있습니다. 그렇다면 제 대답을 친절하게 표시해주십시오. 고마워 :) – EddyTheDove