ActiveableModel::object()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Alish\ActiveableModel\Models;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Model;
7
8
/**
9
 * @property Carbon created_at
10
 * @property bool is_active
11
 */
12
class ActiveableModel extends Model
13
{
14
    public $timestamps = false;
15
16
    protected $guarded = [
17
        'id'
18
    ];
19
20
    protected $casts = [
21
        'created_at' => 'datetime',
22
        'status' => 'bool'
23
    ];
24
25
    protected static function boot()
26
    {
27
        parent::boot();
28
29
        static::creating(function (ActiveableModel $status) {
30
            $status->created_at = $status->freshTimestamp();
31
        });
32
    }
33
34
    public function object()
35
    {
36
        return $this->morphTo();
37
    }
38
}
39