forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResult.php
More file actions
76 lines (67 loc) · 1.83 KB
/
Result.php
File metadata and controls
76 lines (67 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace App\Models;
use App\Enums\ResultService;
use App\Enums\ResultStatus;
use App\Models\Traits\ResultDataAttributes;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Prunable;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Result extends Model
{
use HasFactory, Prunable, ResultDataAttributes;
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = [];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'benchmarks' => 'array',
'data' => 'array',
'healthy' => 'boolean',
'scheduled' => 'boolean',
'service' => ResultService::class,
'status' => ResultStatus::class,
];
}
/**
* Get the prunable model query.
*/
public function prunable(): Builder
{
return static::where('created_at', '<=', now()->subDays(config('speedtest.prune_results_older_than')));
}
/**
* Scope a query to only include completed results.
*/
public function scopeCompleted(Builder $query): Builder
{
return $query->where('status', ResultStatus::Completed);
}
/**
* Get the user who dispatched this speedtest.
*/
public function dispatchedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'dispatched_by');
}
/**
* Determine if the result was unscheduled.
*/
protected function unscheduled(): Attribute
{
return Attribute::make(
get: fn (): bool => ! $this->scheduled,
);
}
}