請幫我一點忙。我正在嘗試按照官方文件為我的 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粉0068477502023-11-09 14:07:52
試試這個
/** @var CachesRoutes $app */ $app = $this->app; if (!$app->routesAreCached()) { Passport::routes(); }
我希望它有用!
P粉5369091862023-11-09 12:22:10
Passport 的路線已移至專用路線檔案中。您可以從應用程式的服務提供者移除 Passport::routes()
呼叫。
此連結可能有幫助