Add fqdn attribute to InstanceSettings model

This commit is contained in:
Andras Bacsai 2023-11-28 12:11:03 +01:00
parent 066f171163
commit d058e04213

View File

@ -3,8 +3,10 @@
namespace App\Models;
use App\Notifications\Channels\SendsEmail;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Spatie\Url\Url;
class InstanceSettings extends Model implements SendsEmail
{
@ -16,6 +18,18 @@ class InstanceSettings extends Model implements SendsEmail
'smtp_password' => 'encrypted',
];
public function fqdn(): Attribute
{
return Attribute::make(
set: function ($value) {
if ($value) {
$url = Url::fromString($value);
$host = $url->getHost();
return $url->getScheme() . '://' . $host;
}
}
);
}
public static function get()
{
return InstanceSettings::findOrFail(0);