HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
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;
    }

}