【Laravel】artisanのmake:factoryコマンドを解説

Laravel

Laravel 10.xのartisanの「make:factory」コマンドを解説します。

Description

新しいモデルファクトリの作成

実際の利用方法はFactory(ファクトリ)を使ってテストでーたを作るを参照

Usage

php artisan make:factory [-m|--model [MODEL]] [--] <name>

Arguments

引数必須説明
name必須ファクトリ名

Options

オプション省略形必須説明
modelm-モデル名。モデル名と作成するファクトリ名が同一の場合は不要

Examples

no options

php artisan make:factory Foo
   INFO  Factory [database/factories/FooFactory.php] created successfully.  
<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Model>
 */
class FooFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            //
        ];
    }
}

Follow me!

コメント

PAGE TOP
タイトルとURLをコピーしました