라 라벨을 배우고 있습니다. 나는 cars 테이블에 자동차를 나열하는 양식을 만들고 클릭하면 선택한 자동차의 데이터를 반환하는 DB 쿼리 ($ modelesc로 식별 됨)를 기반으로하는 다른 양식으로 전송합니다.
이 양식은 데이터를 "주문"테이블로 보냅니다. 지금 가지고있는 코드로는 주문 테이블에 주문을 게시 할 수 없습니다. "RouteCollection.php 라인 233의 MethodNotAllowedHttpException :"이라는 메시지가 나타납니다.
이것은 코드입니다
Web.php
Route::get('catalog', 'carController@catalog');
Route::get('orders/', 'CarController@orders')->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' => 'CarController@orders', '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();
주문 기능 업데이트
public function orders(Request $request)
{
$modelesc = $request->modelesc;
$cars = DB::table('cars')->where('Model', $modelesc)->get();
...
}
Catalog.blade.php
Form::hidden('modelesc', $car->Model)
value
숨겨진 입력에 의해 읽을 수 있습니다 request->modelesc
당신은 URL로 endup 것 같은 모습 http://mysite.dev/orders?modelesc=toyota
.
몇개의 충고
양식을 사용하여 숨겨진 입력 만 제출합니다. 사용자 입력이 없습니다. 간단한 앵커를 사용하는 것이 더 쉬울 것 같습니다 <a></a>
.
@foreach($cars as $car)
<a href="/orders?{{ $car->Model }}">{{ $car->Model }}</a>
@endforeach
같은 결과.
예쁜 URL로 멋지게 만드세요. 경로 정의 변경
Route::get('orders/{modelesc}', 'CarController@orders')->name('orders');
그리고 앵커
<a href="/orders/{{ $car->Model }}">{{ $car->Model }}</a>
이름이 지정된 경로
<a href="{{ route('orders', $car->Model) }}">{{ $car->Model }}</a>
그리고 기능
public function orders($modelesc)
{
$cars = DB::table('cars')->where('Model', $modelesc)->get();
...
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다