Add generic return type to relations in child of Illuminate\Database\Eloquent\Model
use App\Account;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class User extends Model
{
+ /** @return HasMany<Account> */
public function accounts(): HasMany
{
return $this->hasMany(Account::class);
}
}
Configure your rector.php
:
<?php
use RectorLaravel\Rector\ClassMethod\AddGenericReturnTypeToRelationsRector;
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withRules([
AddGenericReturnTypeToRelationsRector::class,
]);