Skip to content

Commit 3af639f

Browse files
committed
feat: add model`s trait DeferredRelations
1 parent 5279d12 commit 3af639f

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Check MD [online][check-online].
99

1010
## [unreleased]
1111

12+
## [1.7.0] - 2021-09-29
13+
14+
### Added
15+
16+
- Add model's trait `DeferredRelations`:
17+
1218
## [1.6.0] - 2021-08-27
1319

1420
### Added
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Php\Support\Laravel\Traits\Models;
6+
7+
use Illuminate\Database\Eloquent\Model;
8+
9+
/**
10+
* @mixin Model
11+
*/
12+
trait DeferredRelations
13+
{
14+
protected static array $deferredRelations = [];
15+
16+
public static function addDeferredRelation(string $relation, mixed $callback): void
17+
{
18+
self::$deferredRelations[$relation] = $callback;
19+
}
20+
21+
public static function getDeferredRelation(string $relation): mixed
22+
{
23+
return self::$deferredRelations[$relation];
24+
}
25+
26+
public static function getDeferredRelations(): array
27+
{
28+
return self::$deferredRelations;
29+
}
30+
31+
public static function unsetDeferredRelation($relation): void
32+
{
33+
unset(self::$deferredRelations[$relation]);
34+
}
35+
36+
public static function unsetDeferredRelations(): void
37+
{
38+
self::$deferredRelations = [];
39+
}
40+
}

0 commit comments

Comments
 (0)