Completed
Pull Request — master (#33)
by Karl
02:24
created

Token::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php namespace JobApis\JobsToMail\Models;
2
3
use Illuminate\Database\Eloquent\Model;
4
5
class Token extends Model
6
{
7
    /**
8
     * Indicates that the IDs are not auto-incrementing.
9
     *
10
     * @var bool
11
     */
12
    public $incrementing = false;
13
14
    /**
15
     * The attributes that are mass assignable.
16
     *
17
     * @var array
18
     */
19
    protected $fillable = [
20
        'user_id',
21
        'type',
22
    ];
23
24
    /**
25
     * The primary key for the model.
26
     *
27
     * @var string
28
     */
29
    protected $primaryKey = 'token';
30
31
    /**
32
     * The name of the "updated at" column.
33
     *
34
     * @var string
35
     */
36
    const UPDATED_AT = null;
37
38
    /**
39
     * Boot function from laravel.
40
     */
41 2
    protected static function boot()
42
    {
43 2
        parent::boot();
44
45 2
        static::creating(function ($model) {
46
            // Generate a secure random token
47
            $model->{$model->getKeyName()} = bin2hex(random_bytes(16));
48 2
        });
49 2
    }
50
51
    /**
52
     * Defines the relationship to User model
53
     *
54
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
55
     */
56
    public function user()
57
    {
58
        return $this->belongsTo(User::class);
59
    }
60
61
    /**
62
     * Converts the Token model to a string by simply returning the "token" value
63
     *
64
     * @return string
65
     */
66
    public function __toString()
67
    {
68
        return $this->token;
69
    }
70
}
71