Skip to content

Commit cfc59d1

Browse files
committed
has creator additional
1 parent 071d18c commit cfc59d1

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/Traits/HasCreator.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)