Add website() to CompanyPresenter

This commit is contained in:
Benjamin Beganović 2021-09-14 11:28:10 +02:00
parent fdd2023098
commit 8dd09be143

View File

@ -12,6 +12,7 @@
namespace App\Models\Presenters;
use App\Models\Country;
use Illuminate\Support\Str;
/**
* Class CompanyPresenter.
@ -139,4 +140,24 @@ class CompanyPresenter extends EntityPresenter
{
return $this->entity->size ? $this->entity->size->name : '';
}
/**
* Return company website URL.
*
* @return string
*/
public function website(): string
{
$website = $this->entity->getSetting('website');
if (empty($website)) {
return $website;
}
if (Str::contains($website, ['http', 'https'])) {
return $website;
}
return \sprintf('http://%s', $website);
}
}