laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.44k stars 11k forks source link

Undefined property: Illuminate\\Database\\Eloquent\\Relations\\HasMany::$orWhere #50172

Closed streamingsystems closed 8 months ago

streamingsystems commented 8 months ago

Laravel Version

10.45.0

PHP Version

8.3.3

Database Driver & Version

mysql

Description

Hi,

I upgrade each week to the latest Laravel. When I upgraded today from 10.44.0 to 10.45.0 and I am now getting this stack trace.

2024-02-20 21:29:08] web.ERROR: Undefined property: Illuminate\Database\Eloquent\Relations\HasMany::$orWhere {"exception":"[object] (ErrorException(code: 0): Undefined property: Illuminate\Database\Eloquent\Relations\HasMany::$orWhere at

The Line in my code looks like this:

->when(!$series, function ($query) { $query->notSeries()->orWhere->book()->orWhere->speaker(); })

This has worked for a long time (years) and stopped today.

I looked through the fixes that went into 10.45.0 and can't seem to determine what might have caused it.

I just reverted back to 10.44.0 and it's working again so I am sure it's in 10.45.0.

Thanks!

Steps To Reproduce

n/a (not sure how to reproduce short of the code I wrote above)

nuernbergerA commented 8 months ago

This is caused by #50124 we already pinned v10.44 due to massive failures.

nuernbergerA commented 8 months ago

added a PR with a currently failing test that passes with v10.44 and below #50176

siarheipashkevich commented 8 months ago

The same issue also

devnicolas1 commented 8 months ago

Not sure if exactly related, but I'm also having an issue caused by https://github.com/laravel/framework/pull/50124 in a Laravel Nova project.

Being more specific, the trait Illuminate\Support\Traits\Tappable that was added to the Relation class seems to cause a type hint problem with our custom Nova filters and a few other Nova methods. For example:

App\Nova\Resource::indexQuery(): Return value must be of type Illuminate\Database\Eloquent\Builder, Staudenmeir\EloquentHasManyDeep\HasManyDeep returned {"userId":2,"exception":"[object] (TypeError(code: 0): App\\Nova\\Resource::indexQuery(): Return value must be of type Illuminate\\Database\\Eloquent\\Builder, Staudenmeir\\EloquentHasManyDeep\\HasManyDeep returned at /srv/app/Nova/Resource.php:31)

The indexQuery method came directly from Nova docs and wasn't even modified by us.

App\Nova\Filters\Subscriptions\Type::apply(): Return value must be of type Illuminate\Database\Eloquent\Builder, Illuminate\Database\Eloquent\Relations\HasManyThrough returned {"userId":2,"exception":"[object] (TypeError(code: 0): App\\Nova\\Filters\\Subscriptions\\Type::apply(): Return value must be of type Illuminate\\Database\\Eloquent\\Builder, Illuminate\\Database\\Eloquent\\Relations\\HasManyThrough returned at /srv/app/Nova/Filters/Subscriptions/Type.php:32)

This one is a custom filter we have. It is defined using Nova 3 way of creating filters, and although our project is currently using Nova 4, it worked just fine until Laravel 10.45.

Again, removing the trait Tappable from Relation seems to solve the issue.

I'm probably opening a new issue for this if it doesn't get fixed in 10.46, but until that, I'll at least add these details.