This repository was archived by the owner on Apr 16, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ class ServiceGenerator extends Generator
28
28
protected $ directories = [
29
29
'Console/ ' ,
30
30
'database/ ' ,
31
+ 'database/factories/ ' ,
31
32
'database/migrations/ ' ,
32
33
'database/seeds/ ' ,
33
34
'Http/ ' ,
@@ -70,6 +71,8 @@ public function generate($name)
70
71
71
72
$ this ->addWelcomeViewFile ($ path );
72
73
74
+ $ this ->addModelFactory ($ path );
75
+
73
76
return new Service (
74
77
$ name ,
75
78
$ slug ,
@@ -197,4 +200,17 @@ protected function getStub()
197
200
{
198
201
return __DIR__ .'/stubs/service.stub ' ;
199
202
}
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
+ }
200
216
}
Original file line number Diff line number Diff line change
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
+ });
Original file line number Diff line number Diff line change @@ -3,12 +3,35 @@ namespace {{namespace}};
3
3
4
4
use View;
5
5
use Lang;
6
+ use Illuminate\Database\Eloquent\Factory as EloquentFactory;
6
7
use Illuminate\Support\ServiceProvider;
7
8
use {{namespace}}\RouteServiceProvider;
8
9
use Illuminate\Translation\TranslationServiceProvider;
9
10
10
11
class {{name}}ServiceProvider extends ServiceProvider
11
12
{
13
+ /**
14
+ * Bootstrap migrations and factories for:
15
+ * - `php artisan migrate` command.
16
+ * - factory() helper.
17
+ *
18
+ * Previous usage:
19
+ * php artisan migrate --path=src/Services/{{name}}/database/migrations
20
+ * Now:
21
+ * php artisan migrate
22
+ *
23
+ * @return void
24
+ */
25
+ public function boot()
26
+ {
27
+ $this->loadMigrationsFrom([
28
+ realpath(__DIR__ . '/../database/migrations')
29
+ ]);
30
+
31
+ $this->app->make(EloquentFactory::class)
32
+ ->load(realpath(__DIR__ . '/../database/factories'));
33
+ }
34
+
12
35
/**
13
36
* Register the {{name}} service provider.
14
37
*
You can’t perform that action at this time.
0 commit comments