Home  >  Q&A  >  body text

routesAreCached() method in Laravel is undefined

Please give me a little help. I'm trying to set up passport for my Laravel application following the official documentation. But I'm stuck on the steps I need to check before calling Passport::routes(). My vscode shows error

Undefined method: routesAreCached()

Even when I trace back to the base abstract class ServiceProvider.php, the code there seems to call $this->app->routesAreCached() without any issues. Below is my AppProvidersAuthServiceProvider.php code.

<?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粉304704653P粉304704653316 days ago610

reply all(2)I'll reply

  • P粉006847750

    P粉0068477502023-11-09 14:07:52

    Try this

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

    I hope it works!

    reply
    0
  • P粉536909186

    P粉5369091862023-11-09 12:22:10

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

    reply
    0
  • Cancelreply