laravel-ide-helper
laravel-ide-helper copied to clipboard
Question about factories autocompletion
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;
@mfn Do you have any idea ?
Sorry, no idea; don't use this feature
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.
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!