-
Notifications
You must be signed in to change notification settings - Fork 0
/
Model.php
54 lines (43 loc) · 1.23 KB
/
Model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
declare(strict_types=1);
namespace Pandawa\Component\Eloquent;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Str;
use Pandawa\Component\Eloquent\Traits\HasAttributesTrait;
use Pandawa\Component\Eloquent\Traits\HasRelationshipsTrait;
use Pandawa\Component\Eloquent\Traits\HasSaveCallbacksTrait;
/**
* @author Iqbal Maulana <iq.bluejack@gmail.com>
*/
abstract class Model extends Eloquent
{
use HasRelationshipsTrait,
HasAttributesTrait,
HasSaveCallbacksTrait;
protected static ?string $resourceName = null;
/**
* Guarded fields.
*
* @var string[]
*/
protected $guarded = [];
/**
* Hidden fields.
*
* @var string[]
*/
protected $hidden = ['pivot'];
public static function resourceName(): string
{
if (null !== $resourceName = static::$resourceName) {
return $resourceName;
}
$name = substr(static::class, (int)strrpos(static::class, '\\') + 1);
return Str::snake($name);
}
public function hasRelation(string $name): bool
{
return method_exists($this, $name) && $this->{$name}() instanceof Relation;
}
}