Illuminate\Routing\Router is macroable, and third-party packages may extend its functionality in the boot() method of their service provider (e.g. https://laravel.com/docs/11.x/http-client#macros).
In 8.x, defineRoutes was called after getPackageProviders. In 9.x, this commit changed that order, which causes router macros to no longer be available when registering routes:
composer require orchestra/testbench:9 and a package that macros routes, like glhd/gretel
Mount the corresponding service provider in getPackageProviders (relevant source)
defineRoutes and try to reference the newly-defined macro (->breadcrumb in this case)
The following error is thrown:
BadMethodCallException: Method Illuminate\Routing\Route::breadcrumb does not exist.
<?php
use Orchestra\Testbench\TestCase;
use Glhd\Gretel\Support\GretelServiceProvider;
class Repro extends TestCase
{
protected function getPackageProviders($app)
{
return [GretelServiceProvider::class];
}
public function defineRoutes($router)
{
$router->get('/profile')
->breadcrumb('Profile'); // `->breadcrumb` fails because its macro hasn't been registered
}
}
Description:
Illuminate\Routing\Router
is macroable, and third-party packages may extend its functionality in theboot()
method of their service provider (e.g. https://laravel.com/docs/11.x/http-client#macros).In 8.x,
defineRoutes
was called aftergetPackageProviders
. In 9.x, this commit changed that order, which causes router macros to no longer be available when registering routes:Steps To Reproduce:
composer require orchestra/testbench:9
and a package that macros routes, likeglhd/gretel
getPackageProviders
(relevant source)defineRoutes
and try to reference the newly-defined macro (->breadcrumb
in this case)The following error is thrown: