Closed francoism90 closed 2 years ago
To answer my own question:
<?php
namespace App\Providers;
use Faker\Factory;
use Faker\Generator;
use Illuminate\Support\ServiceProvider;
use Spatie\Enum\Laravel\Faker\FakerEnumProvider;
use Illuminate\Database\Eloquent\Factories\Factory as Factories;
class FakerServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton(Generator::class, function ($app) {
$faker = Factory::create();
$faker->addProvider(new FakerEnumProvider($faker));
return $faker;
});
}
public function boot()
{
Factories::guessFactoryNamesUsing(function (string $modelName) {
return 'Database\\Factories\\'.class_basename($modelName).'Factory';
});
}
}
Hmm, still:
Call to undefined method Database\Factories\PostFactory::randomEnum()
Yep.. I'm not awake yet:
'status' => $this->faker->randomEnum(Status::class),
I did:
'status' => $this->randomEnum(Status::class),
Sorry for the noise.
I would like to register this provider in
AppServiceProvider
:Result:
Unknown format "text"
It seems it cannot find the default Faker factories/methods, any tips?Thanks!