mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-30 17:47:20 +01:00
Moved more stuff into actions, and made one endpoint for homepage data
This commit is contained in:
37
app/Actions/GetSpeedtestTimeData.php
Normal file
37
app/Actions/GetSpeedtestTimeData.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Speedtest;
|
||||
use Cache;
|
||||
use Carbon\Carbon;
|
||||
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface;
|
||||
|
||||
class GetSpeedtestTimeData implements ActionInterface
|
||||
{
|
||||
/**
|
||||
* Run the action.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function run($days = 7)
|
||||
{
|
||||
$ttl = Carbon::now()->addDays(1);
|
||||
|
||||
return Cache::remember('speedtest-days-' . $days, $ttl, function () use ($days) {
|
||||
$showFailed = (bool)SettingsHelper::get('show_failed_tests_on_graph')->value;
|
||||
|
||||
if ($showFailed === true) {
|
||||
return Speedtest::where('created_at', '>=', Carbon::now()->subDays($days))
|
||||
->orderBy('created_at', 'asc')
|
||||
->get();
|
||||
}
|
||||
|
||||
return Speedtest::where('created_at', '>=', Carbon::now()->subDays($days))
|
||||
->where('failed', false)
|
||||
->orderBy('created_at', 'asc')
|
||||
->get();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user