File: D:/HostingSpaces/SBogers10/ste.komma.pro/app/Base/HasUspTrait.php
<?php
namespace App\Base;
use Illuminate\Support\Collection;
trait HasUspTrait
{
private Collection $usp;
protected int $amountOfUsp = 3;
public function hasUsp(): bool
{
if(!isset($this->usp)) $this->makeUsp();
return $this->usp->isNotEmpty();
}
public function getUsp(): Collection
{
if(!isset($this->usp)) $this->makeUsp();
return $this->usp;
}
/**
* Make the Usp because upon the amount of defined Usp
* and the used (translation) model.
*/
private function makeUsp(): void
{
$usp = collect();
for($u = 1; $u <= $this->amountOfUsp; $u++) {
$uspText = $this->{'usp_' . $u};
if(empty($uspText)) continue;
$usp->push($uspText);
}
$this->usp = $usp;
}
}