2016-11-11 63 views
0

我在laravel有一條路由,我試圖建立。我正在使用版本5.2.45Laravel api路由器無法正常工作獲取錯誤消息

這裏是我的route.php文件:

Route::group(['prefix' => 'api/v1'], function() { 

    Route::resource('prayer', 'PrayerController', [ 
    'except' => ['edit', 'create'] 
    ]); 

    Route::resource('prayer/list', 'ListController', [ 
    'only' => ['store', 'destroy'] 
    ]); 

    Route::post('user', [ 
    'uses' => '[email protected]' 
    ]); 

    Route::post('user/signin', [ 
    'uses' => '[email protected]' 
    ]); 

}); 

這裏是我的AuthController.php文件:

<?php 

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 

use App\Http\Requests; 

class AuthController extends Controller 
{ 
    public function store(Request $request) 
    { 
     return "Request Works!"; 
    } 

    public function signin(Request $request) 
    { 
     return "It Works"; 
    } 
} 

所以,當我去我的路線:http://localhost:8000/api/v1/user我看到這個錯誤:

Whoops, looks like something went wrong. 

1/1 MethodNotAllowedHttpException in RouteCollection.php line 218: 

in RouteCollection.php line 218 

at RouteCollection->methodNotAllowed(array('POST')) in RouteCollection.php line 205 

at RouteCollection->getRouteForMethods(object(Request), array('POST')) in RouteCollection.php line 158 

at RouteCollection->match(object(Request)) in Router.php line 821 

at Router->findRoute(object(Request)) in Router.php line 691 

at Router->dispatchToRoute(object(Request)) in Router.php line 675 

at Router->dispatch(object(Request)) in Kernel.php line 246 

at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) 

at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52 

at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44 

at CheckForMaintenanceMode->handle(object(Request), object(Closure)) 

at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), 
array(object(Request), object(Closure))) in Pipeline.php line 136 

at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) 

at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32 

at Pipeline->Illuminate\Routing\{closure}(object(Request)) 

at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103 

at Pipeline->then(object(Closure)) in Kernel.php line 132 

at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99 

at Kernel->handle(object(Request)) in index.php line 54 

at require_once('/Applications/MAMP/htdocs/rosary-api/api/public/index.php') in server.php line 21 

不知道這裏發生了什麼,因爲當我在瀏覽器中訪問它們時,我的所有其他路線都起作用。但在郵遞員中,他們沒有一個真正的工作。我只是開始與Laravel,所以所有的幫助真正感激!

回答

0

您的路線文件中沒有與您的請求相匹配的路線。所以,你可以做兩件事情:

  1. 添加資源路線用戶
  2. 添加這樣一個GET路線:

Route::get('user', [ 'uses' => '[email protected]' ]);

請記住:從你的瀏覽器的請求始終是GET 。

+0

謝謝!我曾嘗試過,但對郵遞員的郵寄請求,它不適用於我的路線... –

+0

當然,對於POST請求,你需要一個郵政路線;) – Marten

+0

澄清 - 似乎有郵遞員和問題。我更新到最新版本,它工作。此外,您的GET路線代碼的作品! –