From 12c4116fc0a6059743a3c55441955bd4081977dd Mon Sep 17 00:00:00 2001 From: Danilo Giacomi Date: Wed, 26 Jun 2024 12:37:30 +0200 Subject: [PATCH 1/2] added the ability to use resolveRelationUsing and still use the package --- src/Fields/Relations/BelongsTo.php | 2 +- src/Fields/Relations/BelongsToMany.php | 2 +- src/Fields/Relations/HasMany.php | 2 +- src/Fields/Relations/HasOne.php | 2 +- src/QueryToMany.php | 2 +- src/QueryToOne.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Fields/Relations/BelongsTo.php b/src/Fields/Relations/BelongsTo.php index c8f97a8..dad2dfd 100644 --- a/src/Fields/Relations/BelongsTo.php +++ b/src/Fields/Relations/BelongsTo.php @@ -58,7 +58,7 @@ public function fill(Model $model, ?array $identifier): void { $name = $this->relationName(); - assert(method_exists($model, $name), sprintf( + assert(method_exists($model, $name) || $model->relationResolver($model::class, $name), sprintf( 'Expecting method %s to exist on model %s.', $name, $model::class, diff --git a/src/Fields/Relations/BelongsToMany.php b/src/Fields/Relations/BelongsToMany.php index 541a3b2..e940482 100644 --- a/src/Fields/Relations/BelongsToMany.php +++ b/src/Fields/Relations/BelongsToMany.php @@ -150,7 +150,7 @@ private function getRelation(Model $model): EloquentBelongsToMany { $name = $this->relationName(); - assert(method_exists($model, $name), sprintf( + assert(method_exists($model, $name) || $model->relationResolver($model::class, $name), sprintf( 'Expecting method %s to exist on model %s.', $name, $model::class, diff --git a/src/Fields/Relations/HasMany.php b/src/Fields/Relations/HasMany.php index 56b04b9..3ebd37b 100644 --- a/src/Fields/Relations/HasMany.php +++ b/src/Fields/Relations/HasMany.php @@ -159,7 +159,7 @@ private function getRelation(Model $model): EloquentHasMany|EloquentMorphMany { $name = $this->relationName(); - assert(method_exists($model, $name), sprintf( + assert(method_exists($model, $name) || $model->relationResolver($model::class, $name), sprintf( 'Expecting method %s to exist on model %s.', $name, $model::class, diff --git a/src/Fields/Relations/HasOne.php b/src/Fields/Relations/HasOne.php index f4c9968..4901528 100644 --- a/src/Fields/Relations/HasOne.php +++ b/src/Fields/Relations/HasOne.php @@ -100,7 +100,7 @@ public function fill(Model $model, ?array $identifier): void { $name = $this->relationName(); - assert(method_exists($model, $name), sprintf( + assert(method_exists($model, $name) || $model->relationResolver($model::class, $name), sprintf( 'Expecting method %s to exist on model %s.', $name, $model::class, diff --git a/src/QueryToMany.php b/src/QueryToMany.php index 4c201b1..e412e63 100644 --- a/src/QueryToMany.php +++ b/src/QueryToMany.php @@ -152,7 +152,7 @@ private function getRelation(): EloquentRelation { $name = $this->relation->relationName(); - assert(method_exists($this->model, $name), sprintf( + assert(method_exists($this->model, $name) || $this->model->relationResolver($this->model::class, $name), sprintf( 'Expecting method %s to exist on model %s', $name, $this->model::class, diff --git a/src/QueryToOne.php b/src/QueryToOne.php index ec5d342..fceb903 100644 --- a/src/QueryToOne.php +++ b/src/QueryToOne.php @@ -90,7 +90,7 @@ private function getRelation(): EloquentRelation { $name = $this->relation->relationName(); - assert(method_exists($this->model, $name), sprintf( + assert(method_exists($this->model, $name) || $this->model->relationResolver($this->model::class, $name), sprintf( 'Expecting method %s to exist on model %s', $name, $this->model::class, From 78cd1bb817b77f3e0c3b63dd4be13b77532c3454 Mon Sep 17 00:00:00 2001 From: Christopher Gammie Date: Wed, 26 Jun 2024 19:44:54 +0100 Subject: [PATCH 2/2] docs: update changelog and bump version --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e92fe4a..98d740b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. This projec ## Unreleased +## [4.1.0] - 2024-06-26 + +### Added + +- [#36](https://github.com/laravel-json-api/eloquent/pull/36) Support Eloquent dynamic relationships. + ## [4.0.0] - 2024-03-12 ### Changed