Files
newznab-tmux/app/Models/GrabStat.php
T
2025-10-26 22:12:10 +01:00

28 lines
812 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class GrabStat extends Model
{
use HasFactory;
protected $guarded = [];
public static function insertTopGrabbers(): void
{
$users = User::query()->selectRaw('id, username, SUM(grabs) as grabs')->groupBy('id', 'username')->having('grabs', '>', 0)->orderByDesc('grabs')->limit(10)->get();
// Insert data into the grab_stats table
foreach ($users as $user) {
self::updateOrCreate(['username' => $user->username], ['grabs' => $user->grabs]);
}
}
public static function getTopGrabbers(): array
{
return self::query()->select(['username', 'grabs'])->orderByDesc('grabs')->limit(10)->get()->toArray();
}
}