Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Builder<${MODEL}> is not subtype of native type#57921

Unanswered
mattvb91 asked this question inGeneral
Discussion options

Hi everyone,

Im going through the process of upgrading through laravel / larastan versions and im stuck on this issue at the moment. There is a related one but it seems to be due to morph relations.#54590 (comment)

I have the following HasOne relation:

    /**     * @return HasOne<Licence, $this>     */    public function licence(): HasOne    {        return $this->hasOne(Licence::class, 'id', 'id');    }

and im trying to use it like this:

 Tenant::whereHas('licence', function ($query): void {            $query->where('type', Licence::FULL)                ->where('expires_on', '>', now()->timestamp);        })

This results in:

  14     Parameter #1 $column of method Illuminate\Database\Eloquent\Builder<TRelatedModel of Illuminate\Database\Eloquent\Model>::where() expects array<int|model property of T           RelatedModel of Illuminate\Database\Eloquent\Model, mixed>|(Closure(Illuminate\Database\Eloquent\Builder<TRelatedModel>): Illuminate\Database\Eloquent\Builder<TRelated           Model>)|(Closure(Illuminate\Database\Eloquent\Builder<TRelatedModel>): void)|Illuminate\Contracts\Database\Query\Expression|model property of TRelatedModel of Illumina           te\Database\Eloquent\Model, 'type' given.                                                                                                                                🪪  argument.type                                                                                                                                                                 💡  Type #5 from the union: The given string should be a property of TRelatedModel of Illuminate\Database\Eloquent\Model, type given.                                                   15     Parameter #1 $column of method Illuminate\Database\Eloquent\Builder<TRelatedModel of Illuminate\Database\Eloquent\Model>::where() expects array<int|model property of T           RelatedModel of Illuminate\Database\Eloquent\Model, mixed>|(Closure(Illuminate\Database\Eloquent\Builder<TRelatedModel>): Illuminate\Database\Eloquent\Builder<TRelated           Model>)|(Closure(Illuminate\Database\Eloquent\Builder<TRelatedModel>): void)|Illuminate\Contracts\Database\Query\Expression|model property of TRelatedModel of Illumina           te\Database\Eloquent\Model, 'expires_on' given.

Now I try and specify which builder to give it:

Tenant::whereHas('licence', function (Builder $query): void {            /** @var Builder<Licence> $query */

Which removes the 2 errors above but is replaced with:

  16     PHPDoc tag @var with type Illuminate\Database\Eloquent\Builder<App\Models\System\Licence> is not subtype of native type Illuminate\Database\Eloquent\Builder<Illuminate           \Database\Eloquent\Model>.                                                                                                                                                        🪪  varTag.nativeType

Kind of stuck here and cant find any further similar issues. Anyone with some suggestions or even a changelog I can read?

You must be logged in to vote

Replies: 2 comments

Comment options

Sorry it jumped to the laravel discussions.

Edit: Ah nevermind the other topic was in here too so ill keep it here. I thought this was larastan specific

You must be logged in to vote
0 replies
Comment options

Try to replace whereHas with whereRelationHas

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Labels
None yet
2 participants
@mattvb91@TomOusselin

[8]ページ先頭

©2009-2025 Movatter.jp