We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 071d18c commit cfc59d1Copy full SHA for cfc59d1
src/Traits/HasCreator.php
@@ -0,0 +1,33 @@
1
+<?php
2
+
3
+namespace Iqbalatma\LaravelServiceRepo\Traits;
4
5
+use App\Models\User;
6
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
7
8
+/**
9
+ * @property string created_by_id
10
+ * @property User created_by
11
+ */
12
+trait HasCreator
13
+{
14
+ /**
15
+ * @return string
16
17
+ public function getCreatorColumnName(): string
18
+ {
19
+ $createdByColumn = 'created_by_id';
20
+ if (property_exists(static::class, 'createdByColumn')) {
21
+ $createdByColumn = $this->createdByColumn;
22
+ }
23
+ return $createdByColumn;
24
25
26
27
+ * @return BelongsTo
28
29
+ public function created_by(): BelongsTo
30
31
+ return $this->belongsTo(User::class, $this->getCreatorColumnName(), "id");
32
33
+}
0 commit comments