2017-04-24 58 views
1

我在表單提交時收到「MethodNotAllowedHttpException」錯誤,但我找不到原因。這裏是我的形式,Laravel集體形式的創建者創建:MethodNotAllowedHttpException Post on Laravel錯誤

{!! Form::open(['url' => 'photographer/listing/store', 'method'=>'POST', 'files' => true]) !!} 

    //Bunch of Form Inputs here: 

    {!!Form::submit('Create Listing')!!} 
    {!! Form::close() !!} 

那麼這裏就是我的路線:

Route::post('photographer/listing/store', '[email protected]'); 

最後,這裏是控制器:

class PhotographerController extends Controller 
{ 
     public function storeListing(Request $request) 
      { 


      //Form Validation 

      //Store in the database 

      return redirect('/photographer'); 

      } 

} 

從我已經看到,當你對請求使用不正確的方法時,出現這個錯誤,例如。路線是一個獲取形式是一個職位,但這不是這種情況,所以我不知道發生了什麼。

更新:我還包括來自php artisan route:list的相關信息,以及在這裏:

POST  | photographer/listing/store  |       | App\Http\Controllers\[email protected]    | web,auth:photographer 
GET|HEAD | photographer     | photographer.dashboard | App\Http\Controllers\[email protected]      | web,auth:photographer 
+0

嘗試在窗體中設置絕對URL。像這樣'['url'=>'/ photographer/listing/store'...]'。我甚至建議你[命名](https://laravel.com/docs/5.4/routing#named-routes)你的路線,並用'route(name)'調用它們。 – devk

+0

試過了,沒有工作。 –

+0

嘗試使用網址助手:''url'=> url('photographer/listing/store')' –

回答

0

你檢查,其中,關於表單動作的URL是正確的?

我的猜測是以下行:

{!! Form::open(['url' => 'photographer/listing/store', 'method'=>'POST', 'files' => true]) !!} 

沒有指向你所期望的相對URL。嘗試在url參數中添加正斜槓,如下所示:

{!! Form::open(['url' => '/photographer/listing/store', 'method'=>'POST', 'files' => true]) !!} 
相關問題