Completed
Push — master ( 60840d...857394 )
by Mahmoud
03:05
created

FactoriesLoaderTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A changeTheDefaultFactoriesPath() 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 (server/database/factories) as the
19
     * path to the factories, this function changes the path to load
20
     * the factories from the port directory.
21
     */
22
    public function changeTheDefaultFactoriesPath()
23
    {
24
        $newFactoriesPath = '/app/Port/Factory/Factories';
25
26
        App::singleton(Factory::class, function ($app) use ($newFactoriesPath) {
27
            $faker = $app->make(Generator::class);
28
29
            return Factory::construct($faker, base_path() . $newFactoriesPath);
30
        });
31
    }
32
33
}
34