Skip to content

Commit

Permalink
Merge branch '4.x' into optimize-table-blade-components
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Oct 14, 2024
2 parents 4fd9670 + 1d07822 commit 09a40f6
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/tables/src/Table/Concerns/HasQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\HasOneOrMany;
use Illuminate\Database\Eloquent\Relations\Relation;

use function Livewire\invade;
Expand Down Expand Up @@ -141,9 +142,19 @@ public function getInverseRelationship(): ?string
return null;
}

return $this->evaluate($this->inverseRelationship) ?? (string) str(class_basename($relationship->getParent()::class))
->plural()
->camel();
$inverseRelationship = $this->evaluate($this->inverseRelationship);

if ($inverseRelationship) {
return $inverseRelationship;
}

$parentModelClass = str(class_basename($relationship->getParent()::class));

if ($relationship instanceof HasOneOrMany) {
return (string) $parentModelClass->singular()->camel();
}

return (string) $parentModelClass->plural()->camel();
}

public function getInverseRelationshipFor(Model $record): Relation | Builder
Expand Down

0 comments on commit 09a40f6

Please sign in to comment.