Показывает мои id
6 или 7 только первые 2 раза, а после этого все время остается пустым.Это мой код:
@php
$advertisment = DB::table('advertisment')
->orderBy('id', 'desc')
->get();
$random = rand(100, 100000000000000);
$random1 = $random / 1000000000000;
$totalbudget = $advertisment->sum('budget');
$closest = null;
$closestAd = false;
foreach ($advertisment as $ad) {
// first get percentage of total for this budget:
$thisPercent = ($ad->budget * 100) / $totalbudget;
if ($closest === null || abs($random1 - $closest) > abs($thisPercent - $random1 )) {
if ($thisPercent > $random1 || $thisPercent == $random1) {
$closest = $thisPercent;
$closestAd = $ad;
echo $closestAd->id;
}
}
}
@endphp