File: D:/HostingSpaces/SBogers10/ste.komma.pro/app/Base/HasTabsTrait.php
<?php
namespace App\Base;
use Illuminate\Support\Collection;
trait HasTabsTrait
{
private Collection $tabs;
protected int $amountOfTabs = 4;
public function hasTabs(): bool
{
if(!isset($this->tabs)) $this->makeTabs();
return $this->tabs->isNotEmpty();
}
public function getTabs(): Collection
{
if(!isset($this->tabs)) $this->makeTabs();
return $this->tabs;
}
/**
* Make the tabs because upon the amount of defined tabs
* and the used (translation) model.
*/
private function makeTabs(): void
{
$tabs = collect();
for($t = 1; $t <= $this->amountOfTabs; $t++) {
$tabName = $this->{'tab_' . $t . '_name'};
$tabDescription = $this->{'tab_' . $t . '_description'};
if(empty($tabName) || empty($tabDescription)) continue;
$tabs->push((object)[
'name' => $tabName,
'description' => nl2br($tabDescription),
]);
}
$this->tabs = $tabs;
}
}