Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Last active October 11, 2019 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save james2doyle/0983364225874658e5f8144d67870798 to your computer and use it in GitHub Desktop.
Save james2doyle/0983364225874658e5f8144d67870798 to your computer and use it in GitHub Desktop.
Load model factories from a different folder in Laravel. Useful for tests that use vendor factories
<?php
// load factories from a different folder - useful for legacy vendor packages
$this->app->singleton(\Illuminate\Database\Eloquent\Factory::class, function ($app) {
$faker = $app->make(\Faker\Generator::class);
return \Illuminate\Database\Eloquent\Factory::construct($faker, base_path('tests/database/factories'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment