Skip to content

Problem when using custom extension #8

@martinsoenen

Description

@martinsoenen

Sometimes, when using a custom extension in Laravel Seeders, Faker says that the extension is already required.

  INFO  Caching framework bootstrap, configuration, and metadata.  


  config ........................................................ 43.61ms FAIL


   ErrorException 


  [XEFI FAKER] The 'custom-extension' extension is already registered


  at vendor/xefi/faker-php/src/Container/Traits/HasExtensions.php:71

     67▕      */

     68▕     protected function addExtension(Extension $extension): Container

     69▕     {

     70▕         if (isset(static::$extensions[$extension->getName()])) {

  ➜  71▕             trigger_error(sprintf('[XEFI FAKER] The \'%s\' extension is already registered', $extension->getName()), E_USER_WARNING);

     72▕         }

     73▕ 

     74▕         static::$extensions[$extension->getName()] = $extension;

     75▕


      +4 vendor frames 


  5   app/Providers/FakerServiceProvider.php:13

      Xefi\Faker\Faker::__call("resolveExtensions")

      +7 vendor frames 


  13  [internal]:0

      Illuminate\Foundation\Application::{closure:Illuminate\Foundation\Application::boot():1131}(Object(App\Providers\FakerServiceProvider), "App\Providers\FakerServiceProvider")

2025-12-10T15:25:02.752756432Z
 

In the FakerServiceProvider, if we add Container::starting(), the problem is solved.

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Xefi\Faker\Faker;
use App\Faker\CustomExtension;

class FakerServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        faker()->resolveExtensions([CustomExtension::class]);
    }
}

We need to fix it or update the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions