Completed
Push — master ( 8c9c54...6d4889 )
by Elf
44:15
created

FreshCreatedAt::freshTimestamp()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
ccs 0
cts 0
cp 0
c 0
b 0
f 0
nc 1
1
<?php
2
3
namespace ElfSundae\Support\Traits\Eloquent;
4
5
trait FreshCreatedAt
6
{
7
    /**
8
     * Set the value of the "created at" attribute.
9
     *
10
     * @param  mixed  $value
11
     * @return $this
12
     */
13
    abstract public function setCreatedAt($value);
14
15
    /**
16
     * Get a fresh timestamp for the model.
17
     *
18
     * @return \Carbon\Carbon
19
     */
20
    abstract public function freshTimestamp();
21
22
    /**
23
     * Boot the trait.
24
     *
25
     * Add a creating observer, set the value of the "created_at" attribute.
26
     */
27
    protected static function bootFreshCreatedAt()
28
    {
29
        static::creating(function ($model) {
30
            $model->setCreatedAt($model->freshTimestamp());
31
        });
32
    }
33
}
34