Passed
Pull Request — master (#6)
by
unknown
05:06
created

UserToken::user()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Models;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8
use IonGhitun\MysqlEncryption\Models\BaseModel;
9
10
/**
11
 * Class UserToken
12
 *
13
 * @property int $id
14
 * @property int $user_id
15
 * @property string $token
16
 * @property int $type
17
 * @property Carbon|null $expire_on
18
 * @property Carbon|null $created_at
19
 * @property Carbon|null $updated_at
20
 *
21
 * @property User $user
22
 *
23
 * @method static Builder|UserToken newModelQuery()
24
 * @method static Builder|UserToken newQuery()
25
 * @method static Builder|UserToken query()
26
 * @method static Builder|UserToken whereCreatedAt($value)
27
 * @method static Builder|UserToken whereExpireOn($value)
28
 * @method static Builder|UserToken whereId($value)
29
 * @method static Builder|UserToken whereToken($value)
30
 * @method static Builder|UserToken whereType($value)
31
 * @method static Builder|UserToken whereUpdatedAt($value)
32
 * @method static Builder|UserToken whereUserId($value)
33
 * @method static Builder|BaseModel orWhereEncrypted($column, $value)
34
 * @method static Builder|BaseModel orWhereNotEncrypted($column, $value)
35
 * @method static Builder|BaseModel orderByEncrypted($column, $direction)
36
 * @method static Builder|BaseModel whereEncrypted($column, $value)
37
 * @method static Builder|BaseModel whereNotEncrypted($column, $value)
38
 *
39
 * @package App\Models
40
 */
41
class UserToken extends Model
42
{
43
    /** @var int */
44
    const TYPE_REMEMBER_ME = 1;
45
46
    /** @var bool */
47
    public $timestamps = true;
48
49
    /** @var string */
50
    protected $table = 'user_tokens';
51
52
    /** @var array */
53
    protected $fillable = [
54
        'user_id',
55
        'token',
56
        'type',
57
        'expire_on'
58
    ];
59
60
    /** @var array */
61
    protected $casts = [
62
        'type' => 'int'
63
    ];
64
65
    /**
66
     * User.
67
     *
68
     * @return BelongsTo
69
     */
70
    public function user()
71
    {
72
        return $this->belongsTo(User::class, 'user_id', 'id');
73
    }
74
75
    /**
76
     * @param $value
77
     *
78
     * @return Carbon
79
     */
80
    public function getExpireOnAttribute($value)
81
    {
82
        if ($value !== null) {
83
            return Carbon::parse($value);
84
        }
85
86
        return null;
87
    }
88
}
89