laravel-ide-helper icon indicating copy to clipboard operation
laravel-ide-helper copied to clipboard

Question about factories autocompletion

Open ahmed-aliraqi opened this issue 4 years ago • 4 comments

Is there a way to add autocompletion to factories create and make methods to return model instance? if not, what the best way to add this feature ? 🤔

for example:

/**
 * @method \App\Models\User create($attributes = [], ?Model $parent = null)
 * @method \App\Models\User createOne($attributes = [])
 * @method \Illuminate\Database\Eloquent\Collection|\App\Models\User[] createMany(iterable $records)
 * @method \App\Models\User make($attributes = [], ?Model $parent = null)
 * @method \App\Models\User makeOne($attributes = [])
 */
class UserFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = User::class;

ahmed-aliraqi avatar Apr 02 '21 20:04 ahmed-aliraqi

@mfn Do you have any idea ?

ahmed-aliraqi avatar Apr 02 '21 20:04 ahmed-aliraqi

Sorry, no idea; don't use this feature

mfn avatar Apr 02 '21 21:04 mfn

Doesn't using the class generated by the artisan ide-helper:meta command as a mixin fix this?

/**
 * @mixin UserFactoryBuilder
 */
class UserFactory extends Factory
{

It would work as long as your factory class' methods match the ones from Illuminate\Database\Eloquent\FactoryBuilder.

uuf6429 avatar May 18 '21 07:05 uuf6429

I confirm adding docblocks like @ahmed-aliraqi is suggesting works (in PHPStorm, at least), but that would be a nice addition if it could be generated by the package!

beNjiox avatar Aug 17 '21 11:08 beNjiox