From d058e042139673c134a8547a45849147cdb77954 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 28 Nov 2023 12:11:03 +0100 Subject: [PATCH] Add fqdn attribute to InstanceSettings model --- app/Models/InstanceSettings.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/Models/InstanceSettings.php b/app/Models/InstanceSettings.php index 057595351..846148159 100644 --- a/app/Models/InstanceSettings.php +++ b/app/Models/InstanceSettings.php @@ -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);