Skip to content
This repository was archived by the owner on Apr 16, 2024. It is now read-only.

Commit 94d9242

Browse files
author
Alex Giuvara
committed
Add ModelFactory
1 parent 4de6e54 commit 94d9242

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/Generators/ServiceGenerator.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public function generate($name)
7171

7272
$this->addWelcomeViewFile($path);
7373

74+
$this->addModelFactory($path);
75+
7476
return new Service(
7577
$name,
7678
$slug,
@@ -198,4 +200,17 @@ protected function getStub()
198200
{
199201
return __DIR__.'/stubs/service.stub';
200202
}
203+
204+
/**
205+
* Add the ModelFactory file.
206+
*
207+
* @param string $path
208+
*/
209+
public function addModelFactory($path)
210+
{
211+
$modelFactory = file_get_contents(__DIR__ . '/stubs/model-factory.stub');
212+
$this->createFile($path . '/database/factories/ModelFactory.php', $modelFactory);
213+
214+
unset($modelFactory);
215+
}
201216
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
|--------------------------------------------------------------------------
5+
| Model Factories
6+
|--------------------------------------------------------------------------
7+
|
8+
| Here you may define all of your model factories. Model factories give
9+
| you a convenient way to create models for testing and seeding your
10+
| database. Just tell the factory how a default model should look.
11+
|
12+
*/
13+
14+
$factory->define('User namespace here', function (Faker\Generator $faker) {
15+
/**
16+
* @var string
17+
*/
18+
static $password;
19+
20+
return [
21+
'name' => $faker->name,
22+
'email' => $faker->safeEmail,
23+
'password' => $password ?: $password = bcrypt('secret'),
24+
'remember_token' => str_random(10)
25+
];
26+
});

0 commit comments

Comments
 (0)