MethodNotAllowedHttpException RouteCollection.php 第 218 行
MethodNotAllowedHttpException RouteCollection.php line 218
我尝试通过 post 将值传递给 post。我获取 select 值并在创建文件时发送它,此后用户编译其他表单并将其发送到其他路由 post 并检查验证。
但它不起作用。
Route.php
Route::get('administrator/','AdministratorController@index');
Route::get('administrator/select','AdministratorController@select');
Route::post('administrator/create','AdministratorController@create');
Route::post('administrator','AdministratorController@store');
管理员控制器
public function create(Request $request){
$chapterS=SubChapters::where('ChapterName',$request->chapters)->get();
return view('administrator_pages.create',compact('chapterS','request'));
}
public function store(Request $request){
//dd($request->all());
$this->validate($request,['IdQuestion'=>'required']);
return 'store';
}
administrator_pages.create
@extends('app')
@section('content')
{{Form::open(['url'=>'administrator'])}}
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Capitolo Scelto:</span>
{!! Form::text('Chapter',$request->chapters,['class'=>'form-control','readonly'=>'readonly']) !!}
</div>
<br>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Sotto Capitolo: </span>
<div class="dropdown">
<select name="SubChapterID"class="btn btn-default dropdown-toggle">
@foreach($chapterS as $chapter)
<option value="{{$chapter->SubChapterID}}">{{$chapter->SubChapterID}}</option>
@endforeach
</select>
</div>
</div><!--//SUBCHAPTERID-->
<br>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Id Domanda :</span>
{!! Form::text('IdQuestion',null,['class'=>'form-control']) !!}
</div><!-- ID QUESTION -->
<br>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Immagine: </span>
{!! Form::text('UrlImg',null,['class'=>'form-control']) !!}
</div><!-- URL IMG-->
<br>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Domanda:</span>
{!! Form::textarea('Contenent',null,['class'=>'form-control','rows'=>'5']) !!}
</div><!-- Contenet -->
<br>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Risposta:</span>
<!-- <div class="form-control"> -->
{!! Form::radio('Answer', 'Vero') !!} Vero
{!! Form::radio('Answer', 'Falso') !!} Falso
</div>
<!-- </div>-->
<br>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Spiegazione:</span>
{!! Form::textarea('Explanation',null,['class'=>'form-control','rows'=>'5']) !!}
</div><!-- Explanation-->
<br>
{!! Form::submit('Avanti',['class'=>'btn btn-default']) !!}
{{Form::close()}}
@if($errors->any())
<ul class="alert alert-danger">
@foreach($errors->all() as $error)
<li>{{$error}}</li>
@endforeach
</ul>
@endif
@stop
错误
1/1 MethodNotAllowedHttpException in RouteCollection.php line 218:
in RouteCollection.php line 218
at RouteCollection->methodNotAllowed(array('POST')) in RouteCollection.php line 205
at RouteCollection->getRouteForMethods(object(Request), array('POST')) in RouteCollection.php line 158
at RouteCollection->match(object(Request)) in Router.php line 821
at Router->findRoute(object(Request)) in Router.php line 691
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 54
尝试改变
{{Form::open(['url'=>'administrator'])}}
在您的 administrator_pages.create
文件中
{{Form::open(['url'=>'administrator/create'])}}
原因:
您想在提交表单时调用 AdministratorController@create
函数。 URL 在 routes.php
中这样定义
Route::post('administrator/create','AdministratorController@create');
当然,正如@sachith 提到的,您的 create
请求应该是 GET.
如此看来
{{Form::open(['method' => 'GET', 'url'=>'administrator/create'])}}
并且在routes.php
Route::get('administrator/create','AdministratorController@create');
为什么你要 post 值到 create
函数?应该是这样的,
Route::get('administrator/create','AdministratorController@create');
我尝试通过 post 将值传递给 post。我获取 select 值并在创建文件时发送它,此后用户编译其他表单并将其发送到其他路由 post 并检查验证。 但它不起作用。 Route.php
Route::get('administrator/','AdministratorController@index');
Route::get('administrator/select','AdministratorController@select');
Route::post('administrator/create','AdministratorController@create');
Route::post('administrator','AdministratorController@store');
管理员控制器
public function create(Request $request){
$chapterS=SubChapters::where('ChapterName',$request->chapters)->get();
return view('administrator_pages.create',compact('chapterS','request'));
}
public function store(Request $request){
//dd($request->all());
$this->validate($request,['IdQuestion'=>'required']);
return 'store';
}
administrator_pages.create
@extends('app')
@section('content')
{{Form::open(['url'=>'administrator'])}}
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Capitolo Scelto:</span>
{!! Form::text('Chapter',$request->chapters,['class'=>'form-control','readonly'=>'readonly']) !!}
</div>
<br>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Sotto Capitolo: </span>
<div class="dropdown">
<select name="SubChapterID"class="btn btn-default dropdown-toggle">
@foreach($chapterS as $chapter)
<option value="{{$chapter->SubChapterID}}">{{$chapter->SubChapterID}}</option>
@endforeach
</select>
</div>
</div><!--//SUBCHAPTERID-->
<br>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Id Domanda :</span>
{!! Form::text('IdQuestion',null,['class'=>'form-control']) !!}
</div><!-- ID QUESTION -->
<br>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Immagine: </span>
{!! Form::text('UrlImg',null,['class'=>'form-control']) !!}
</div><!-- URL IMG-->
<br>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Domanda:</span>
{!! Form::textarea('Contenent',null,['class'=>'form-control','rows'=>'5']) !!}
</div><!-- Contenet -->
<br>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Risposta:</span>
<!-- <div class="form-control"> -->
{!! Form::radio('Answer', 'Vero') !!} Vero
{!! Form::radio('Answer', 'Falso') !!} Falso
</div>
<!-- </div>-->
<br>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Spiegazione:</span>
{!! Form::textarea('Explanation',null,['class'=>'form-control','rows'=>'5']) !!}
</div><!-- Explanation-->
<br>
{!! Form::submit('Avanti',['class'=>'btn btn-default']) !!}
{{Form::close()}}
@if($errors->any())
<ul class="alert alert-danger">
@foreach($errors->all() as $error)
<li>{{$error}}</li>
@endforeach
</ul>
@endif
@stop
错误
1/1 MethodNotAllowedHttpException in RouteCollection.php line 218:
in RouteCollection.php line 218
at RouteCollection->methodNotAllowed(array('POST')) in RouteCollection.php line 205
at RouteCollection->getRouteForMethods(object(Request), array('POST')) in RouteCollection.php line 158
at RouteCollection->match(object(Request)) in Router.php line 821
at Router->findRoute(object(Request)) in Router.php line 691
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 54
尝试改变
{{Form::open(['url'=>'administrator'])}}
在您的 administrator_pages.create
文件中
{{Form::open(['url'=>'administrator/create'])}}
原因:
您想在提交表单时调用 AdministratorController@create
函数。 URL 在 routes.php
中这样定义
Route::post('administrator/create','AdministratorController@create');
当然,正如@sachith 提到的,您的 create
请求应该是 GET.
如此看来
{{Form::open(['method' => 'GET', 'url'=>'administrator/create'])}}
并且在routes.php
Route::get('administrator/create','AdministratorController@create');
为什么你要 post 值到 create
函数?应该是这样的,
Route::get('administrator/create','AdministratorController@create');