Factory autocompletion

By @boris · 2021-08-30 14:36

Factory autocompletion

Add autocompletion to your Laravel factories.

I've created a simple stub that adds some extra docblocks to newly created factories. Publish it to the stubs directory, and the next time you generate a factory, it will contain them.

Example

<?php

namespace {{ factoryNamespace }};

use Illuminate\Database\Eloquent\Factories\Factory;
use {{ namespacedModel }};

/**
 * @method {{ model }}|\Illuminate\Support\Collection<{{ model }}> create($attributes = [], ?Model $parent = null)
 * @method \Illuminate\Support\Collection<{{ model }}> createMany(iterable $records)
 * @method {{ model }} createOne($attributes = [])
 * @method {{ model }}|\Illuminate\Support\Collection<{{ model }}> make($attributes = [], ?Model $parent = null)
 * @method {{ model }} makeOne($attributes = [])
 */
class {{ factory }}Factory extends Factory
{
    protected $model = {{ model }}::class;

    public function definition()
    {
        return [
            //
        ];
    }
}