Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Use Laravel's Factories with custom main namespace on Laravel 8
*** On Laravel 8, factories becomes classes.
*** If your are using a custom namespace for your app, you need to add Factory::guessFactoryNamesUsing.
*** There is an example, enjoy 🎊
namespace CustomNamespace\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Factories\Factory;
class AppServiceProvider extends ServiceProvider
* Register any application services.
* @return void
public function register()
public function boot()
Factory::guessFactoryNamesUsing(function (string $model) {
return 'Database\Factories\\' . class_basename($model) . 'Factory';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.