2016-09-06 55 views
0

我的Laravel中的路由有問題。方法PUT和DELETE在Laravel中不起作用

當我使用以下路線:

Route::resource('user', 'PostsController'); 

方法PUT和DELETE做工精細與功能破壞和更新在我的控制器,但是當我使用以下路線:

Route::delete('{$id}', function($id){ 
    return "Remover o usuário ".$id; 
}); 

Route::put('{$id}', function($id){ 
    return "Editar o usuário ".$id; 
}); 

我有以下錯誤:

NotFoundHttpException in RouteCollection.php line 161: 

in RouteCollection.php line 161 
at RouteCollection->match(object(Request)) in Router.php line 780 
at Router->findRoute(object(Request)) in Router.php line 610 
at Router->dispatchToRoute(object(Request)) in Router.php line 596 
at Router->dispatch(object(Request)) in Kernel.php line 267 
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in HandleCors.php line 42 
at HandleCors->handle(object(Request), object(Closure)) in Pipeline.php line 137 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46 
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104 
at Pipeline->then(object(Closure)) in Kernel.php line 149 
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116 
at Kernel->handle(object(Request)) in index.php line 56 
at require_once('C:\xampp\htdocs\apiRest\public\index.php') in server.php line 21 

婁按照圖像更多的細節我怎麼送

Request

我使用Postsman發送請求的請求。

請問誰能幫助我?

回答

3

在Laravel中定義路徑參數時沒有使用$,而是使用{id}而不是{$id}。有關更多信息,請參閱docs

所以你的情況:

Route::delete('{id}', function($id){ 
    return "Remover o usuário ".$id; 
}); 

和:

Route::put('{id}', function($id){ 
    return "Editar o usuário ".$id; 
}); 
+0

工作正常!謝啦 –