Completed
Push — master ( f8b6bf...bec27e )
by Mahmoud
03:02
created

FactoriesLoaderTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A loadContainerFactories() 0 10 1
1
<?php
2
3
namespace App\Port\Loader\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 loadContainerFactories()
22
    {
23
        $newFactoriesPath = '/app/Port/Loader/Loaders/Factories';
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