2016-07-07 2 views
0

임에 geting하지만 난Laravel 5.1 컨트롤러에 데이터를 게시하려고하지만 내 컨트롤러에 <code>POST</code> 데이터하려고 MethodNotAllowedHttpException 오류를

MethodNotAllowedHttpException in RouteCollection.php line 219:

오류 메시지가지고있어, 여기 내 파일입니다.

내 경로 파일

<?php 

Route::get('/', function() { 
    return view('welcome'); 
}); 

// Authentication routes 
Route::get('auth/login', 'Auth\[email protected]'); 
Route::post('auth/login', 'Auth\[email protected]'); 
Route::get('auth/logout', 'Auth\[email protected]'); 

// Registration routes 
Route::get('register', 'Auth\[email protected]'); 
Route::post('auth/register', 'Auth\[email protected]'); 
Route::controllers(['password' => 'Auth\PasswordController',]); 

Route::get('/home', '[email protected]'); 

// Using A Route Closure 
Route::get('profile', ['middleware' => 'auth', function() { 
    // Only authenticated users may enter... 
    Route::auth(); 
}]); 

// practicing using forms for sending data to the DB & populating form fields with DB data 
Route::get('profile', '[email protected]'); 
Route::post('profile/update', '[email protected]'); 

profile.blade.php

<form method="POST" action="/profile/update/"> 
    <div class="form-group hidden"> 
     <input type="hidden" name="id" value="<?php echo $users[0]->id;?>"> 
     <input type="hidden" name="_token" value="{{ csrf_token() }}"> 
     <input name="_method" type="hidden" value="PATCH"> 
    </div> 
    <div class="form-group"> 
     <label for="email"><b>Name:</b></label> 
     <input type="text" name="name" placeholder="Please enter your email here" class="form-control"/> 
    </div> 
    <div class="form-group"> 
     <label for="email"><b>Email:</b></label> 
     <input type="text" name="email" placeholder="Please enter your email here" class="form-control"/> 
    </div> 
    <div class="form-group"> 
     <button type="submit" class="btn btn-default"> Submit </button> 
    </div> 
</form> 

& 내 ProfileController.php

<?php 

namespace App\Http\Controllers; 

use Auth; 
use App\User; 
use Illuminate\Http\Request; 

use App\Http\Requests; 
use App\Http\Controllers\Controller; 

class ProfileController extends Controller 
{ 
    /** 
    * Update user profile & make backend push to DB 
    **/ 

    public function index() 
    { 
     if(Auth::check()) { 
      // connecting to the DB and accessing 
      $users = User::all(); 
      //var_dump($users); 

      return view('profile', compact('users')); 
     } 

     return view('auth/login'); 
    } 

    public function updateProfile(Requests $request) { 

     return $request->all(); 

    } 
} 

문제가 무엇인지 확실하지. 모든 도움을 모두 주셔서 감사합니다

+0

@ MarcoAurélioDeleu가 내 질문에 대한 답변을 –

+0

@ MarcoAurélioDeleu 님이'POST '에'PATCH '를 (를) 추가해야하는 곳을 읽으려고 시도 했습니까? –

+0

@ MarcoAurélioDeleu ive가 'route :: patch'에 대한 내 경로를 업데이트했지만 같은 오류가 발생했습니다. –

답변

1

우리가 여기서 해결하기 위해 관리 문제의 몇 :

이상 사용 HTTP 동사보기에서

의, 당신은이 : <form method="POST"뿐만 아니라 <input name="_method" type="hidden" value="PATCH">하는 수도 POSTPATCH 사이의 충돌 routes.phpPOST만을 선언 했으므로 patch 정의를 삭제 해주세요.

라우팅 실수가보기에 여전히

action="/profile/update/"로 액션 포인트 경로가 Route::post('profile/update')로 정의되는 동안, 양식의 끝에 추가 /을 알 수 있습니다. 그 슬래시가 있으면 안된다. 그 Laravel 내 폴더가 아닌 클래스이기 때문에 use App\Http\Requests; 아마 잘못된 :

컨트롤러 당신은 여기가

요청합니다. 그것을 제거하고 지금 use Illuminate\Http\Request;을 유지합시다. 가까운 장래에 양식 요청을 작성하는 방법을 배우게 될 것이며 UpdateProfileRequest.php을 원할 것입니다.

관련 문제