Passed
Push — main ( 69451c...874877 )
by Garbuz
03:25
created

src/Models/Token.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Garbuzivan\Laraveltokens\Models;
6
7
/** @scrutinizer ignore-type */
8
use App\Models\User;
0 ignored issues
show
The type App\Models\User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Carbon\Carbon;
10
use Illuminate\Database\Eloquent\Factories\HasFactory;
11
use Illuminate\Database\Eloquent\Model;
12
use Illuminate\Database\Eloquent\Relations\BelongsTo;
13
14
class Token extends Model
15
{
16
    use HasFactory;
17
18
    protected $table = 'tokens';
19
20
    /**
21
     * @var string[]
22
     */
23
    protected $fillable = [
24
        'token',
25
        'user_id',
26
        'title',
27
        'expiration',
28
        'last_use',
29
    ];
30
31
    /**
32
     * @var string[]
33
     */
34
    protected $dates = [
35
        'expiration',
36
        'last_use',
37
        'created_at',
38
        'updated_at',
39
    ];
40
41
    /**
42
     * The attributes that should be hidden for arrays.
43
     *
44
     * @var array
45
     */
46
    protected $hidden = [];
47
48
    /**
49
     * The attributes that should be casted to native types.
50
     *
51
     * @var array
52
     */
53
    protected $casts = [
54
        'id' => 'integer',
55
        'token' => 'string',
56
        'user_id' => 'integer',
57
        'title' => 'string',
58
        'expiration' => 'datetime',
59
        'last_use' => 'datetime',
60
    ];
61
62
    /**
63
     * Validation rules
64
     *
65
     * @var array
66
     */
67
    public static array $rules = [
68
        'token' => 'required',
69
    ];
70
71
    /**
72
     * Relation to wallet
73
     * @return BelongsTo
74
     */
75
    public function user(): BelongsTo
76
    {
77
        return $this->belongsTo(User::class, 'user_id', 'id');
78
    }
79
80
    /**
81
     * Проверка валидности токена по дате
82
     * @return bool
83
     */
84
    public function isValid(): bool
85
    {
86
        return $this->expiration > Carbon::now();
87
    }
88
}
89