Tip always show one item

This commit is contained in:
Cüneyt Şentürk 2022-11-02 17:01:32 +03:00
parent 072900e240
commit c9e3fc4dda

View File

@ -52,6 +52,10 @@ class Tips extends Component
$view = 'components.tips.relative'; $view = 'components.tips.relative';
} }
if ($this->tips->count() > 1) {
$view = 'components.tips.relative';
}
return view($view); return view($view);
} }
@ -71,6 +75,10 @@ class Tips extends Component
return; return;
} }
$rows = collect();
shuffle($tips);
foreach ($tips as $tip) { foreach ($tips as $tip) {
if ($tip->position != $this->position) { if ($tip->position != $this->position) {
continue; continue;
@ -84,7 +92,13 @@ class Tips extends Component
$tip->action = Str::replace('{company_id}', company_id(), $tip->action); $tip->action = Str::replace('{company_id}', company_id(), $tip->action);
} }
$this->tips->push($tip); $rows->push($tip);
}
if ($rows->count()) {
$row = $rows->shuffle()->first();
$this->tips->push($row);
} }
} }
} }