Completed
Push — master ( 7eefd3...6db0a4 )
by Mahmoud
03:27
created

loadFactoriesFromContainers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace App\Ship\Engine\Loaders;
4
5
use App;
6
use Faker\Generator;
7
use Illuminate\Database\Eloquent\Factory;
8
9
/**
10
 * Class FactoriesLoaderTrait.
11
 *
12
 * @author  Mahmoud Zalt <[email protected]>
13
 */
14
trait FactoriesLoaderTrait
15
{
16
17
    /**
18
     * By default Laravel takes a shared factory directory to load from it all the factories.
19
     * This function changes the path to load the factories from the port directory instead.
20
     */
21
    public function loadFactoriesFromContainers()
22
    {
23
        $newFactoriesPath = '/app/Ship/Engine/Loaders/FactoryMixer';
24
25
        App::singleton(Factory::class, function ($app) use ($newFactoriesPath) {
26
            $faker = $app->make(Generator::class);
27
28
            return Factory::construct($faker, base_path() . $newFactoriesPath);
29
        });
30
    }
31
32
}
33