laravel MethodNotAllowedHttpException RouteCollection.php 第 218 行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39176108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MethodNotAllowedHttpException RouteCollection.php line 218
提问by Davide Minelli
I try to pass a value by post to post. I take the select value and send it at create file, after this the user compile other form and send it to other route post and check the validation. But it doesn't work. Route.php
我尝试通过帖子传递一个值。我采用选择值并将其发送到创建文件,然后用户编译其他表单并将其发送到其他路由帖子并检查验证。但它不起作用。 路由.php
Route::get('administrator/','AdministratorController@index');
Route::get('administrator/select','AdministratorController@select');
Route::post('administrator/create','AdministratorController@create');
Route::post('administrator','AdministratorController@store');
AdministratorController
管理员控制器
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
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
Error
错误
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
采纳答案by Sachith Muhandiram
Why are you post values to create
function? It should be like,
为什么要发布值以create
发挥作用?应该是这样的
Route::get('administrator/create','AdministratorController@create');
回答by linuxartisan
Try changing
尝试改变
{{Form::open(['url'=>'administrator'])}}
in your administrator_pages.create
file to
在你的administrator_pages.create
文件中
{{Form::open(['url'=>'administrator/create'])}}
Reason:You want to call the AdministratorController@create
function on form submission. The URL for that is defined in the routes.php
like so
原因:您想AdministratorController@create
在表单提交时调用该函数。对于该URL的定义routes.php
,像这样
Route::post('administrator/create','AdministratorController@create');
And of course, as @sachith mentioned, your create
request should be GET.
当然,正如@sachith 提到的,您的create
请求应该是GET。
So in view
所以在看来
{{Form::open(['method' => 'GET', 'url'=>'administrator/create'])}}
And in routes.php
而在 routes.php
Route::get('administrator/create','AdministratorController@create');