Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 3 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
ShareHistory | |
0.00% |
0 / 3 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
getResentAttribute | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
flyshare | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
user | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace App\Http\Models; |
4 | |
5 | use App\Http\Models\Auth\User; |
6 | use App\Traits\UpdateResentAt; |
7 | |
8 | class ShareHistory extends Moloquent |
9 | { |
10 | use UpdateResentAt; |
11 | |
12 | /** |
13 | * The time lapse for resending flyshare link via email. |
14 | * |
15 | * @var int |
16 | */ |
17 | public const RESEND_TIME_EXPIRY = 30; |
18 | |
19 | /** |
20 | * The attributes that are mass assignable. |
21 | * |
22 | * @var array |
23 | */ |
24 | protected $fillable = [ |
25 | 'email', 'status', 'registered', 'user_id', 'resent_at', |
26 | ]; |
27 | |
28 | /** |
29 | * The table associated with the model. |
30 | * |
31 | * @var string |
32 | */ |
33 | protected $table = 'share_histories'; |
34 | |
35 | /** |
36 | * The accessors to append to the model's array form. |
37 | * |
38 | * @var array |
39 | */ |
40 | protected $appends = ['resent']; |
41 | |
42 | /** |
43 | * Get the resent atrribute for the share history. |
44 | */ |
45 | public function getResentAttribute(): bool |
46 | { |
47 | return filled($this->resent_at) ? now()->diffInMinutes($this->resent_at->toDateTime()) < self::RESEND_TIME_EXPIRY : false; |
48 | } |
49 | |
50 | /** |
51 | * Get the flyshare that belongs to the history. |
52 | */ |
53 | public function flyshare() |
54 | { |
55 | return $this->belongsTo(FlyShare::class); |
56 | } |
57 | |
58 | /** |
59 | * Get the user that owns the history if the user is registered in the system |
60 | * |
61 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
62 | */ |
63 | public function user() |
64 | { |
65 | return filled($this->user_id) ? $this->belongsTo(User::class) : null; |
66 | } |
67 | } |