ShortLink::getShortUrlAttribute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace danielebuso\shortener\Models;
4
5
use DateTime;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Support\Carbon;
8
9
/**
10
 * Model of the table tasks.
11
 *
12
 * @property string id
13
 * @property string url
14
 * @property string short_url
15
 * @property DateTime|Carbon|null not_before
16
 * @property DateTime|Carbon|null expire_at
17
 * @property boolean enabled
18
 * @property DateTime|Carbon|null created_at
19
 * @property DateTime|Carbon|null updated_at
20
 */
21
class ShortLink extends Model
22
{
23
    /**
24
     * The "type" of the auto-incrementing ID.
25
     *
26
     * @var string
27
     */
28
    protected $keyType = 'string';
29
30
    /**
31
     * The table name that has been migrated.
32
     *
33
     * @var array
34
     */
35
    protected $table = 'short_links';
36
37
    /**
38
     * The attributes that are mass assignable.
39
     *
40
     * @var array
41
     */
42
    protected $fillable = [
43
        'id',
44
        'url',
45
        'not_before',
46
        'expire_at',
47
        'enabled',
48
    ];
49
50
    /**
51
     * The attributes that should be cast to native types.
52
     *
53
     * @var array
54
     */
55
    protected $casts = [
56
        'not_before' => 'datetime',
57
        'expire_at' => 'datetime',
58
    ];
59
60
    /**
61
     * Generate short link url using route
62
     *
63
     * @return string
64
     */
65
    public function getShortUrlAttribute() {
66
        return route('short_link', [$this->id]);
67
    }
68
}
69