Skip to content

Commit

Permalink
✨ ability to stack interfaces onto relations to give pivots - allow n…
Browse files Browse the repository at this point in the history
…ullable interfaces
  • Loading branch information
acidjazz committed Sep 2, 2021
1 parent 04e0c28 commit c15ff08
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/ModelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ public function getRelations(Model $model): array
foreach ($methods as $method) {
$reflection = new ReflectionMethod($model, $method);
if ($reflection->hasReturnType()) {
if ($model->interfaces) {
foreach ($model->interfaces as $key => $value) {
if ($key === $method) {
if (isset($value['nullable']) && $value['nullable'] === true) {
$relations[ $key . '?' ] = $value[ 'name' ];
} else {
$relations[ $key ] = $value[ 'name' ];
}
continue 2;
}
}
}
$type = (string) $reflection->getReturnType();
$code = file($reflection->getFileName())[$reflection->getEndLine()-2];
preg_match('/\((.*?)::class/', $code, $matches);
Expand Down

0 comments on commit c15ff08

Please sign in to comment.