2016-07-07 11 views
0

イムは、私のコントローラにPOSTデータにしようが、私はLaravel 5.1は、コントローラにデータを投稿しようとしているが、

MethodNotAllowedHttpException in RouteCollection.php line 219:

エラーメッセージが出ていMethodNotAllowedHttpExceptionエラーをgeting、ここに私のファイルがあります。

私のルートファイル

<?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élioDeleuiveは私のルートを '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が必要になります。

関連する問題