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

changeTheDefaultFactoriesPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
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