Last active
December 19, 2019 17:28
-
-
Save PeterDKC/b2cc17d1e56b359cbcbe3e8d319f87b3 to your computer and use it in GitHub Desktop.
Extend a Laravel Model Factory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// class Admin extends User | |
$factory->define(App\Admin::class, function (Faker\Generator $faker) { | |
return app(Illuminate\Database\Eloquent\Factory::class) | |
->raw( | |
Package\Models\User::class, | |
[ | |
'foobar' => 'barbaz', | |
'bazqux' => 42 | |
] | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If a package defines a Model
Foobar
and youclass MyFoobar extends Foobar
, you probably also want to create afactory(MyFoobar::class)
for any fields that your child Model provides or anything that overrides the parent Model's fields.