mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-24 06:28:27 +01:00
Added method to get speedtests in last x days
This commit is contained in:
@@ -4,11 +4,49 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Helpers\SpeedtestHelper;
|
||||
use App\Jobs\SpeedtestJob;
|
||||
use App\Speedtest;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class SpeedtestController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$data = Speedtest::paginate();
|
||||
|
||||
return response()->json([
|
||||
'method' => 'index of speedtests',
|
||||
'data' => $data,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function time($days)
|
||||
{
|
||||
$rule = [
|
||||
'days' => [ 'required', 'integer' ],
|
||||
];
|
||||
|
||||
$validator = Validator::make([ 'days' => $days ], $rule);
|
||||
|
||||
if($validator->fails()) {
|
||||
return response()->json([
|
||||
'method' => 'get speedtests in last x days',
|
||||
'error' => $validator->errors(),
|
||||
], 422);
|
||||
}
|
||||
|
||||
$data = Speedtest::where('created_at', '>=', Carbon::now()->subDays($days))
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'method' => 'get speedtests in last x days',
|
||||
'days' => $days,
|
||||
'data' => $data
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function latest()
|
||||
{
|
||||
$data = SpeedtestHelper::latest();
|
||||
|
||||
Reference in New Issue
Block a user