Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Laravel Passport no longer has a routes() method

ErrorCall to undefined method Laravel\Passport\Passport::routes()

Short answer

Passport 11 stopped needing Passport::routes() because it registers its OAuth routes itself, and the method is gone. Delete the call from your service provider. If you changed the routes before, call Passport::ignoreRoutes() in register() and copy the routes you want into routes/web.php.

  • Applies to Laravel 12, Laravel Passport 12 and 13, PHP 8.4
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find every place the method is called, and see which Passport version is installed.

    grep -rn "Passport::routes" app bootstrap routes
    composer show laravel/passport
  2. 2Match what you see, then jump to its fix

    1. 1The grep points at AuthServiceProvider or AppServiceProvider, and the stack trace ends in that lineOld setup code still calls Passport::routes()Fix
    2. 2The call passes a closure or options, such as Passport::routes(function ($router) { ... })The app customised the routes through the old callbackFix

What does the error look like?

  • Call to undefined method Laravel\Passport\Passport::routes()

Cause 1 of 2

Old setup code still calls Passport::routes()

1Check

Older tutorials add Passport::routes() to a service provider. The Passport upgrade guide for 11.0 says the call can be removed because the routes now come from a dedicated route file.

grep -rn "Passport::routes" app bootstrap

2Fix

Delete the call. Do nothing else for the default /oauth routes.

// remove this line from the provider
// Passport::routes();

3Verify

The routes are still registered after the call is gone.

php artisan route:list | grep oauth

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 2

The app customised the routes through the old callback

1Check

The upgrade guide says routes you overrode with the old method can be overridden in your own routes file instead.

grep -rn -A4 "Passport::routes(" app

2Fix

Tell Passport not to register its routes, then copy the ones you need from its routes file into routes/web.php and edit them.

// app/Providers/AppServiceProvider.php
use Laravel\Passport\Passport;

public function register(): void
{
    Passport::ignoreRoutes();
}

3Verify

Only your copied routes appear.

php artisan route:list | grep oauth

Confirmed by laravel.com

Did this fix it?

How do I stop it coming back?

  • Read the package's upgrade guide before every major version bump.
  • Keep setup code in one provider so leftover calls are easy to find.
  • Run php artisan route:list in CI to notice missing OAuth routes.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require maatwebsite/excel fails to install

Composer says the package needs an older PHP than the one installed

Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.

3 causes, each with a fix

Back end

composer require laravel/horizon fails: ext-pcntl is missing

laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system

Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.