Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel-方法不允许HTTP异常(RouteCollection.php第218行)_Php_Laravel_Laravel 5.3 - Fatal编程技术网

Laravel-方法不允许HTTP异常(RouteCollection.php第218行)

Laravel-方法不允许HTTP异常(RouteCollection.php第218行),php,laravel,laravel-5.3,Php,Laravel,Laravel 5.3,我目前是拉威尔的新手,正在尝试开发我的第一个项目。在开发将数据插入数据库的过程中,RouteCollection.php第218行出现了此方法NotAllowedHttpException错误。我在Google和Stackoverflow中搜索了解决方案,但没有找到与我当前问题相关的解决方案,其中一些解决方案对于这个简单的问题来说太复杂了(我想是的…) 我的表格在我的检查表页面中:- <form action="{{url('addchecklist')}}" method="POST"&

我目前是拉威尔的新手,正在尝试开发我的第一个项目。在开发将数据插入数据库的过程中,RouteCollection.php第218行出现了此
方法NotAllowedHttpException
错误。我在Google和Stackoverflow中搜索了解决方案,但没有找到与我当前问题相关的解决方案,其中一些解决方案对于这个简单的问题来说太复杂了(我想是的…)

我的表格在我的检查表页面中:-

<form action="{{url('addchecklist')}}" method="POST">
            {{ csrf_field() }}
            <div class="row">
                <div class="col-sm-12">
                    <div class="text-left">
                        <input type="hidden" name="schmFK" value="{{$id}}">
                        <div class="col-sm-6">
                            <h4>
                                <label>Section</label>
                                <select class="selectpicker form-control" data-live-search="true" name="sctionPK">
                                    <option selected>Select the Section</option>
                                    @foreach ($sction as $key=>$slct1)
                                    <option value="{{$slct1->ssctionPK}}">{{strtoupper($slct1->ssctionName)}}</option>
                                    @endforeach
                                </select>
                            </h4>
                        </div>
                        <div class="col-sm-2">
                        <button type="button" data-toggle="modal" data-target=".bs-example-modal-lg" class="btn btn-primary btn-sm" style="margin-top:33px; padding-top:7px; padding-bottom:7px;">Add Section</button>
                        </div>
                        <div class="col-sm-4">
                            <h4>
                                <label>Severity</label>
                                <select class="selectpicker form-control" name="svrityPK">
                                    <option selected>Select the Severity</option>
                                    @foreach ($svrity as $key=>$slct2)
                                    <option value="{{$slct2->severityPK}}">{{strtoupper($slct2->severityName)}}</option>
                                    @endforeach
                                </select>
                            </h4>
                        </div>
                        <div class="col-sm-12">
                            <h4>
                                <label>Question</label>
                                <input class="form-control" type="text" placeholder="Question" name="question">
                            </h4>
                        </div>
                        <div class="col-sm-6">
                            @include('widgets.button', array('class'=>'primary btnaddstd', 'size'=>'lg', 'type'=>'submit', 'value'=>'Add Checklist'))
                        </div>
                    </div>
                </div>
            </div>
        </form>
我的场景是这样的,我有一个表单供用户在其中输入数据。然后,当数据被保存时,它们将被重定向到该数据的页面,以便在那里执行某些操作数据已成功保存在数据库中,但重定向到指定页面(addref.blade)时返回最新记录ID错误:-

但是URL指向我希望它指向的地方(意味着URL是正确的):-

如你所见,我从网上找到的常见解决方案是:-

确保routes和form的两种方法相同,并且是:-

method="POST"

Route::post
<form action="{{url('addchecklist')}}" method="POST">

Route::post('/addchecklist', function (Request $request)
确保URL路由能够识别表单的操作URL,并且它是:-

method="POST"

Route::post
<form action="{{url('addchecklist')}}" method="POST">

Route::post('/addchecklist', function (Request $request)

路由::post('/addchecklist',函数(请求$Request)
将CSRF令牌字段包括在表单中,并将其包括在内:-

<form action="{{url('addchecklist')}}" method="POST">
            {{ csrf_field() }}

{{csrf_field()}}

我已经尝试过网络上提供的那些简单的解决方案,但没有什么足够的帮助。我仍然想知道我还错过了什么,希望这里的任何人都能帮助解决我的问题。

你能写:

url(“/addchecklist”)

而不是:

url('addchecklist')

然后打印r('in'); 然后去死,看看你得到了什么

  Route::post('/addchecklist', function (Request $request){

      print_r('in');
      die;
  });

我认为错误在于您有一个未在
路由或web.php
文件中注册的重定向

示例重定向:

Route::post('/addchecklist', function (Request $request){
    //some post process here...

    return redirect('addref/'.$input->cklistPK)
        ->with('src', $src)
        ->with('chkstd', $chkstd)
        ->with('id',$input->cklistPK)
        ->with('schmid', $request->schmFK)
        ->with('chcklst', $chcklst)
        ->with('stddetail', $stddetail)
        ->with('stndrd', $stndrd)
        ->with('sction', $sction);
});

Route::get('addref/{id}', function(Request $request){
     //show the blade.php with data
});

php artisan路由:清除,然后try@JYoThI同样的事情也会发生。你是什么意思?我在我的
web.php
中的路由中有重定向,并且有证据表明,你已经在你的示例中复制了它。在调用任何内部重定向之前,你需要先检查你想要重定向的路由名称是否已在你的web.php中注册laravel找不到。因此,例如,您需要有两个路由。一个用于post方法,另一个用于重定向。因此,您的意思是,我必须创建一个重定向到另一个路由的路由,第二个路由重定向到视图?如下:
路由1(保存数据)->路由2(获取数据和重定向)->查看页面(重定向页面)
?@Kaydarin,是的,或者你也可以使用一个控制器来处理保存过程并使路由更干净。以前从未尝试过这种路由到路由技术,不妨尝试一下。关于控制器,我的错…我只是不想打开太多页面。顺便说一句,从你的示例中,
路由::get('addref/{id}',function(Request$Request)
,它应该是
Route::get('addref/{id}',function($id)
,对吗?因为我不确定第二个路由是否可以读取
Request
。好的,那么您的URL路由工作得很好。路由没有错误。