2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Laravel】Factory以外でFakerを使う

Last updated at Posted at 2019-07-10

Testの場合

traitを読み込む

/* 略 */
class SampleTest extends TestCase {
    use WithFaker;
/* 略 */

$this->fakerが使えるようになる

Test以外の場合

インポートする

use Faker\Factory as FakerFactory;

インスタンスを作る

$faker = FakerFactory::create('ja_JP');

または

$faker = $this->app->make(FakerFactory::class);

$appとか$this->appが存在しない場合は

$faker = resolve(FakerFactory::class);

参考 https://readouble.com/laravel/5.5/ja/container.html

おわり

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?