laravel中的routesarecached()方法未定义

发布于 2025-02-10 04:22:26 字数 1427 浏览 1 评论 0原文

请帮我一点。我正在尝试通过遵循官方文档) 。但是,我陷入了需要在调用Passport :: Routes()之前需要检查的步骤。我的vscode显示了一个错误

未定义的方法:routesarecached()

即使我追溯到基本的Abstract类ServiceProvider.php,那里的代码似乎正在调用$ this-> app-&gt-&gt-; doutesArecached()毫无问题。以下是我的app \ provers \ authserviceprovider.php代码。

<?php

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
use Laravel\Passport\Passport;

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

    /**
     * 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();
         }

    }
}

Please help me out a bit. I'm trying to setup passport for my Laravel app by following the official docs. But i'm stuck at the step where I need to check before calling Passport::routes(). My vscode displayed an error saying

undefined method: routesAreCached()

even though when I traced back to the base abstract class ServiceProvider.php, the code there seems to be calling $this->app->routesAreCached() without any problems. Below is my App\Providers\AuthServiceProvider.php code.

<?php

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
use Laravel\Passport\Passport;

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

    /**
     * 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();
         }

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤单情人 2025-02-17 04:22:27

护照的路线已移至专用路线文件。您可以从应用程序的服务提供商中删除Passport :: Routes()调用。
此链接可能会有所帮助

Passport's routes have been moved to a dedicated route file. You can remove the Passport::routes() call from your application's service provider.
This link may help

恍梦境° 2025-02-17 04:22:27

尝试这个

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

我希望它有用!

Try this

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

i hope it was useful !

很酷不放纵 2025-02-17 04:22:27

使用这个,它将起作用

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

Use this , It will work

public function boot()
{
    $this->registerPolicies();
    
    /** @var CachesRoutes $app */
    $app = $this->app;
    if (!$app->routesAreCached()) {
        Passport::routes();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文