Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to load factory in module ? #337

Closed
andhikayuana opened this issue Oct 26, 2017 · 3 comments
Closed

how to load factory in module ? #337

andhikayuana opened this issue Oct 26, 2017 · 3 comments

Comments

@andhikayuana
Copy link

Im trying to load factory permodule to Module like this :

<?php

use Faker\Generator as Faker;

foreach(Module::enabled() as $moduleEnabled){
    $factory->load('app/Modules/'.$moduleEnabled['basename'].'/Database/Factories');
...
}
...

when im execute php artisan module:seed im get this error :

PHP Warning:  Uncaught ErrorException: require(/var/www/html/ajaro/simdes/simdes-api/app/Modules/Core/Database/Factories/CoreFactory.php): failed to open stream: Too many open files in /var/www/html/ajaro/simdes/simdes-api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factory.php:203
Stack trace:
#0 /var/www/html/ajaro/simdes/simdes-api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factory.php(203): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'require(/var/ww...', '/var/www/html/a...', 203, Array)
#1 /var/www/html/ajaro/simdes/simdes-api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factory.php(203): require()
#2 /var/www/html/ajaro/simdes/simdes-api/database/factories/ModelFactory.php(8): Illuminate\Database\Eloquent\Factory->load('app/Modules/Cor...')
#3 /var/www/html/ajaro/simdes/simdes-api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factory.php(203): require('/var/www/html/a...')
#4 /var/www/html/ajaro/simdes/simdes-api/vendor/laravel/framework/src/ in /var/www/html/ajaro/simdes/simdes-api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factory.php on line 203
PHP Fatal error:  Illuminate\Database\Eloquent\Factory::load(): Failed opening required '/var/www/html/ajaro/simdes/simdes-api/app/Modules/Core/Database/Factories/CoreFactory.php' (include_path='.:/usr/share/php') in /var/www/html/ajaro/simdes/simdes-api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Factory.php on line 203
PHP Fatal error:  Uncaught ErrorException: include(/var/www/html/ajaro/simdes/simdes-api/vendor/symfony/debug/Exception/FatalErrorException.php): failed to open stream: Too many open files in /var/www/html/ajaro/simdes/simdes-api/vendor/composer/ClassLoader.php:444
Stack trace:
#0 /var/www/html/ajaro/simdes/simdes-api/vendor/composer/ClassLoader.php(444): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'include(/var/ww...', '/var/www/html/a...', 444, Array)
#1 /var/www/html/ajaro/simdes/simdes-api/vendor/composer/ClassLoader.php(444): include()
#2 /var/www/html/ajaro/simdes/simdes-api/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile('/var/www/html/a...')
#3 [internal function]: Composer\Autoload\ClassLoader->loadClass('Symfony\\Compone...')
#4 /var/www/html/ajaro/simdes/simdes-api/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(136): spl_autoload_call('Symfony\\Compone...')
#5 /var/www/html/ajaro/simdes/simdes-api/vendor/laravel/framework/src/Illuminate/Foun in /var/www/html/ajaro/simdes/simdes-api/vendor/composer/ClassLoader.php on line 444

its behaviour load 1 file in multiple ? and how to load factory manual ?
thanks

@Litiano
Copy link
Contributor

Litiano commented Oct 26, 2017

On ModuleServiceProvider.php add:
` /**
* Register the module services.
*
* @return void
*/
public function register()
{
$this->app->register(RouteServiceProvider::class);

    $this->mergeConfigFrom(
        __DIR__.'/../config.php', 'moduleName'
    );

    $this->registerEloquentFactoriesFrom(__DIR__.'/../Database/Factories');
}

/**
 * Register factories.
 *
 * @param  string  $path
 * @return void
 */
protected function registerEloquentFactoriesFrom($path)
{
    $this->app->make(Factory::class)->load($path);
}

`

@kaidesu kaidesu closed this as completed Oct 26, 2017
@inzamam-idrees
Copy link

inzamam-idrees commented Nov 26, 2018

I am trying to register Module like this:
/**
* Register the module services.
*
* @return void
*/
public function register()
{
$this->app->register(RouteServiceProvider::class);

    $this->mergeConfigFrom(
       __DIR__.'/../config.php', 'tags'
   );

   $this->registerEloquentFactoriesFrom(__DIR__.'/../Database/Factories');
}

/**
 * Register factories.
 *
 * @param  string  $path
 * @return void
*/
protected function registerEloquentFactoriesFrom($path)
{
    $this->app->make(Factory::class)->load($path);
}

Where "tags" is my module slug name. So, I got an error :
Illuminate\Support\ServiceProvider::mergeConfigFrom(): Failed opening required 'F:\xampp\htdocs\laravel-projects\CaffModule\app\Modules\Tags\Providers/../config.php' (include_path='F:\xampp\php\PEAR')

How to I fix it?

@tjhunkin-inhance
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants