Passed
Push — master ( 5d1dbf...ac3204 )
by Paul
04:29
created

AccessToken::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 Devpri\Tinre\Models;
4
5
use Devpri\Tinre\Traits\AuthorizedActions;
6
use Illuminate\Database\Eloquent\Model;
7
8
class AccessToken extends Model
9
{
10
    use AuthorizedActions;
11
12
    protected $actions = ['viewAny', 'view', 'create', 'update', 'delete'];
13
14
    /**
15
     * The attributes that are mass assignable.
16
     *
17
     * @var array
18
     */
19
    protected $fillable = ['name', 'token'];
20
21
    /**
22
     * The attributes that should be hidden for serialization.
23
     *
24
     * @var array
25
     */
26
    protected $hidden = [
27
        'token',
28
    ];
29
    
30
    /**
31
     * The attributes that should be cast.
32
     *
33
     * @var array
34
     */
35
    protected $casts = [
36
        'permissions' => 'array',
37
        'last_used_at' => 'datetime',
38
    ];
39
    
40
    public function user()
41
    {
42
        return $this->belongsTo('Devpri\Tinre\Models\User');
43
    }
44
45
    public static function findToken($token)
46
    {
47
        return static::where('token', hash('sha256', $token))->first();
48
    }
49
}
50