Laravel中的routesAreCached()方法未定義
P粉304704653
P粉304704653 2023-11-08 18:45:24
0
2
603

請幫我一點忙。我正在嘗試按照官方文件為我的 Laravel 應用程式設定護照。但我陷入了在呼叫 Passport::routes() 之前需要檢查的步驟。我的 vscode 顯示錯誤

未定義的方法:routesAreCached()

即使當我追溯到基本抽象類別ServiceProvider.php時,那裡的程式碼似乎呼叫 $this->app->routesAreCached() 沒有任何問題。下面是我的 AppProvidersAuthServiceProvider.php 程式碼。

<?php

namespace AppProviders;

use IlluminateFoundationSupportProvidersAuthServiceProvider as ServiceProvider;
use IlluminateSupportFacadesGate;
use LaravelPassportPassport;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The model to policy mappings for the application.
     *
     * @var array<class-string, class-string>
     */
    protected $policies = [
        // 'AppModelsModel' => 'AppPoliciesModelPolicy',
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();

        /**
         * This method will register the routes necessary to issue access tokens and revoke access tokens, clients, and personal access tokens:
         * 
         */

         if (! $this->app->routesAreCached()) {   // error at this line
            Passport::routes();
         }

    }
}


#
P粉304704653
P粉304704653

全部回覆(2)
P粉006847750

試試這個

/** @var CachesRoutes $app */
    $app = $this->app;
    if (!$app->routesAreCached()) {
        Passport::routes();
    }

我希望它有用!

P粉536909186

Passport 的路線已移至專用路線檔案中。您可以從應用程式的服務提供者移除 Passport::routes() 呼叫。 此連結可能有幫助

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!