routesAreCached() method in Laravel is undefined
P粉304704653
P粉304704653 2023-11-08 18:45:24
0
2
678

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粉304704653
P粉304704653

reply all(2)
P粉006847750

Try this

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

I hope it works!

P粉536909186

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template