Laravel 5路由问题 - 错误的方法调用异常

时间:2015-04-22 00:24:34

标签: php laravel laravel-5

我试图简单地发送一个' PUT'请求我的一个路由(在路由文件中称为资源),但我收到这个回溯作为响应。

Whoops, looks like something went wrong.
1/1 BadMethodCallException in Controller.php line 273: Method [show] does not exist.

    in Controller.php line 273
    at Controller->__call('show', array('1'))
    at AccountControllerV2->show('1')
    at call_user_func_array(array(object(AccountControllerV2), 'show'), array('account' => '1')) in Controller.php line 246
    at Controller->callAction('show', array('account' => '1')) in ControllerDispatcher.php line 162
    at ControllerDispatcher->call(object(AccountControllerV2), object(Route), 'show') in ControllerDispatcher.php line 107
    at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
    at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 108
    at ControllerDispatcher->callWithinStack(object(AccountControllerV2), object(Route), object(Request), 'show') in ControllerDispatcher.php line 67
    at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\API\V2\AccountControllerV2', 'show') in Route.php line 198
    at Route->runWithCustomDispatcher(object(Request)) in Route.php line 131
    at Route->run(object(Request)) in Router.php line 692
    at Router->Illuminate\Routing\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Authenticate.php line 47
    at Authenticate->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
    at Pipeline->then(object(Closure)) in Router.php line 694
    at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 661
    at Router->dispatchToRoute(object(Request)) in Router.php line 619
    at Router->dispatch(object(Request)) in Kernel.php line 214
    at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in HttpsProtocol.php line 15
    at HttpsProtocol->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
    at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
    at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
    at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
    at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
    at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
    at Pipeline->then(object(Closure)) in Kernel.php line 115
    at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
    at Kernel->handle(object(Request)) in index.php line 53

我不能为我的生活弄清楚为什么会这样。

以下是Controller本身的代码片段(扩展了BaseController):

/**
     * Update the currently logged User in storage.
     *
     * @return Response 201
     * @return jsonArray account
     * @return string message
     */

    public function update($account_id) {
        $input = Input::all();
        $message = 'Account Successfully Updated';
        $user = Auth::User();

这是Route声明:

Route::group(array('prefix' => 'api/v2', 'namespace' => 'API\V2', 'middleware' => 'auth'), function()
{
    Route::resource('challenges', 'ChallengeControllerV2', ['only'=> ['index','store','update','destroy']]);
    Route::resource('groups', 'GroupControllerV2');
    Route::resource('account', 'AccountControllerV2');

正在调用正确的路径。任何想法,为什么我得到什么似乎是不合逻辑的回应?没有额外的中间件/过滤器连接到控制器而不是显示的内容。

1 个答案:

答案 0 :(得分:4)

事实证明,如果你没有指定路线上可用的资源,那么在Laravel 5中它会假设它们都存在(与Laravel 4不同,它检查所有控制器中可用的资源)。所以我不得不改变这样的界限。

Route::resource('account', 'AccountControllerV2', ['only'=> ['index','update','destroy']]);