2017-09-12 10 views
0

Laravel 5.5でデータを更新する際に問題があります。リソースコントローラのレコードを更新しようとしているときに、私はMethodNotAllowedExceptionを取得していますが、私はPUTメソッドを使用しています。Laravel 5.5 MethodNot PUTメソッドを使用した更新時に適用されました

ルート:

Route::middleware(['auth'])->group(function(){ 
    Route::get('/', '[email protected]')->name('home') 

    Route::resource('stages', 'StagesController'); 

}); 

フォーム: enter image description here

アヤックス方法:

$('#ajax_form_modal').on('submit', 'form', function (event) { 
    event.preventDefault(); 
    var $modal = $('#ajax_form_modal'); 
    var $modal_dialog = $modal.find('.modal-dialog'); 
    var $form = $(this); 
    var method = 'post'; 

    if ($form.find('[name="_method"]')) { 
     method = $form.find('[name="_method"]').val(); //this fires 
    } else if ($form.has('method')) { 
     method = $form.attr('method'); 
    } 

    //method = 'PUT' 

    $.ajax({ 
     url: $(this).attr('href'), 
     dataType: 'json', 
     type: method, 
     data: $(this).serialize(), 

応答:

"trace": [ 
    { 
     "file": "\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\RouteCollection.php", 
     "line": 238, 
     "function": "methodNotAllowed", 
     "class": "Illuminate\\Routing\\RouteCollection", 
     "type": "->", 
     "args": [ 
      [ 
       "GET", 
       "HEAD", 
       "POST" 
      ] 
     ] 
    }, 

ここでは詳細ですルート:リスト: enter image description here

私はupdateメソッドが唯一の「GET」ことができますなぜない考え、「HEAD」、「POST」を持っていないが、私は、POSTメソッドを使用して手動で更新処理するようにしようと、それは動作しますが、また場所をデバッグしようとしました経路の不一致は起こるが運がない場所。誰かに助言を与えることはできますか?私は本当に私のコントローラのRESTFULを壊すことはしたくありません。

答えて

0

私はバグを見つける:hrefが行動する必要があり、より多くの睡眠を必要とする...

$.ajax({ 
    url: $(this).attr('href'), 
    dataType: 'json', 
    type: method, 
    data: $(this).serialize(), 
関連する問題