onecentlin / laravel5-snippets-vscode

Laravel snippets for Visual Studio Code (Support Laravel 5 and above)
MIT License
36 stars 19 forks source link

Add return type in model relationships snippets #26

Open samir-araujo opened 4 years ago

samir-araujo commented 4 years ago

Thanks a lot for the extension!

It would be nice if when we use Relation:* snippets it also applies return type.

Current example (Relation::hasOne)

public function user()
{
    return $this->hasOne('App\User', 'foreign_key', 'local_key');
}

Suggestion (Relation::hasOne)

public function user(): HasOne
{
    return $this->hasOne('App\User', 'foreign_key', 'local_key');
}
mreduar commented 3 years ago

This functionality requires that the type is required the type class at the beginning of each model, thus filling the number of classes imported to the models. Besides, Laravel does not adopt this behavior in its source code.

Therefore, I consider that it is a very particular case and that not all of us like to include it. But since @onecentlin not to be very active these days, he does not mind to check the pull requests made to him.