diff --git a/packages/forms/src/Components/Select.php b/packages/forms/src/Components/Select.php index 24268ae6ce9..f5d5ff2b76c 100644 --- a/packages/forms/src/Components/Select.php +++ b/packages/forms/src/Components/Select.php @@ -22,6 +22,7 @@ use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasOneOrMany; +use Illuminate\Database\Eloquent\Relations\HasOneOrManyThrough; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Arr; use Illuminate\Support\Str; @@ -816,7 +817,7 @@ public function relationship(string | Closure | null $name = null, string | Clos if ( ($relationship instanceof BelongsToMany) || - ($relationship instanceof HasManyThrough) + ($relationship instanceof (class_exists(HasOneOrManyThrough::class) ? HasOneOrManyThrough::class : HasManyThrough::class)) ) { if ($modifyQueryUsing) { $component->evaluate($modifyQueryUsing, [ @@ -989,7 +990,7 @@ static function (Select $component): bool { if ( ($relationship instanceof HasOneOrMany) || - ($relationship instanceof HasManyThrough) || + ($relationship instanceof (class_exists(HasOneOrManyThrough::class) ? HasOneOrManyThrough::class : HasManyThrough::class)) || ($relationship instanceof BelongsToThrough) ) { return; @@ -1144,7 +1145,7 @@ public function getLabel(): string | Htmlable | null return parent::getLabel(); } - public function getRelationship(): BelongsTo | BelongsToMany | HasOneOrMany | HasManyThrough | BelongsToThrough | null + public function getRelationship(): BelongsTo | BelongsToMany | HasOneOrMany | HasManyThrough | HasOneOrManyThrough | BelongsToThrough | null { if (blank($this->getRelationshipName())) { return null; @@ -1269,7 +1270,7 @@ protected function getQualifiedRelatedKeyNameForRelationship(Relation $relations return $relationship->getQualifiedRelatedKeyName(); } - if ($relationship instanceof HasManyThrough) { + if ($relationship instanceof (class_exists(HasOneOrManyThrough::class) ? HasOneOrManyThrough::class : HasManyThrough::class)) { return $relationship->getQualifiedForeignKeyName(); } diff --git a/packages/panels/src/Resources/Pages/CreateRecord.php b/packages/panels/src/Resources/Pages/CreateRecord.php index c1366b1eccc..eba25857d28 100644 --- a/packages/panels/src/Resources/Pages/CreateRecord.php +++ b/packages/panels/src/Resources/Pages/CreateRecord.php @@ -15,6 +15,7 @@ use Illuminate\Contracts\Support\Htmlable; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasManyThrough; +use Illuminate\Database\Eloquent\Relations\HasOneOrManyThrough; use Illuminate\Support\Js; use Throwable; @@ -182,7 +183,7 @@ protected function associateRecordWithTenant(Model $record, Model $tenant): Mode { $relationship = static::getResource()::getTenantRelationship($tenant); - if ($relationship instanceof HasManyThrough) { + if ($relationship instanceof (class_exists(HasOneOrManyThrough::class) ? HasOneOrManyThrough::class : HasManyThrough::class)) { $record->save(); return $record; diff --git a/packages/tables/src/Actions/CreateAction.php b/packages/tables/src/Actions/CreateAction.php index cc15e44b103..7667eacaa3f 100644 --- a/packages/tables/src/Actions/CreateAction.php +++ b/packages/tables/src/Actions/CreateAction.php @@ -9,6 +9,7 @@ use Filament\Tables\Table; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasOneOrManyThrough; use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Support\Arr; @@ -66,7 +67,7 @@ protected function setUp(): void if ( (! $relationship) || - $relationship instanceof HasManyThrough + $relationship instanceof (class_exists(HasOneOrManyThrough::class) ? HasOneOrManyThrough::class : HasManyThrough::class) ) { $record->save(); diff --git a/packages/tables/src/Filters/Concerns/HasRelationship.php b/packages/tables/src/Filters/Concerns/HasRelationship.php index b37d534ecec..0fa54764883 100644 --- a/packages/tables/src/Filters/Concerns/HasRelationship.php +++ b/packages/tables/src/Filters/Concerns/HasRelationship.php @@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasManyThrough; +use Illuminate\Database\Eloquent\Relations\HasOneOrManyThrough; use Illuminate\Database\Eloquent\Relations\Relation; use Znck\Eloquent\Relations\BelongsToThrough; @@ -110,7 +111,7 @@ public function getRelationshipKey(?Builder $query = null): ?string $relationship->getQualifiedRelatedKeyName(); } - if ($relationship instanceof HasManyThrough) { + if ($relationship instanceof (class_exists(HasOneOrManyThrough::class) ? HasOneOrManyThrough::class : HasManyThrough::class)) { return $query?->getModel()->qualifyColumn($relationship->getForeignKeyName()) ?? $relationship->getQualifiedForeignKeyName(); } diff --git a/packages/tables/src/Table/Concerns/HasQuery.php b/packages/tables/src/Table/Concerns/HasQuery.php index 4f847473bad..f74e7ed44e5 100644 --- a/packages/tables/src/Table/Concerns/HasQuery.php +++ b/packages/tables/src/Table/Concerns/HasQuery.php @@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\Eloquent\Relations\HasOneOrMany; +use Illuminate\Database\Eloquent\Relations\HasOneOrManyThrough; use Illuminate\Database\Eloquent\Relations\Relation; use function Livewire\invade; @@ -88,7 +89,7 @@ public function getRelationshipQuery(): ?Builder $query = $relationship->getQuery(); - if ($relationship instanceof HasManyThrough) { + if ($relationship instanceof (class_exists(HasOneOrManyThrough::class) ? HasOneOrManyThrough::class : HasManyThrough::class)) { // https://github.com/laravel/framework/issues/4962 $query->select($query->getModel()->getTable() . '.*'); diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 0ddd3abee85..ebc8e046c7a 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -12,6 +12,7 @@ parameters: ignoreErrors: - '#Unable to resolve the template type TKey in call to function collect#' - '#Unable to resolve the template type TValue in call to function collect#' + - '#.*Illuminate\\Database\\Eloquent\\Relations\\HasOneOrManyThrough.*#' - message: "#^Parameter \\#1 \\$value of method Filament\\\\Support\\\\Components\\\\Component\\:\\:evaluate\\(\\) expects \\(callable\\(\\)\\: void\\)\\|void, Closure\\(Filament\\\\Forms\\\\Components\\\\BaseFileUpload, Filament\\\\Forms\\\\Get, Filament\\\\Forms\\\\Set\\)\\: void given\\.$#" count: 2