MethodNotAllowedHttpException RouteCollection.php第218行

时间:2016-08-26 23:52:25

标签: laravel laravel-5 laravel-5.2 laravel-5.1 laravel-routing

我尝试通过post传递值到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');

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

@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">&nbsp;-->&nbsp; &nbsp;
{!!            Form::radio('Answer', 'Vero') !!} Vero     &nbsp; &nbsp;
{!!            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

2 个答案:

答案 0 :(得分:2)

尝试更改

{{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');

答案 1 :(得分:2)

为什么要将值发布到http://www.xxxxx.com/aff_c?offer_id=4xxx&aff_id=xxxx&source={var1}&aff_sub={clickid}&aff_sub1={campaign.id}&creative_name={var2}&creative_size={var3}&google_aid=UDID函数?它应该是,

compiler.resolvers.normal.plugin('resolve', function resolverPlugin(request, cb) {
  ... 
});