coolify/app/Models/InstanceSettings.php

67 lines
1.7 KiB
PHP
Raw Normal View History

2023-03-28 13:47:37 +00:00
<?php
namespace App\Models;
2023-06-06 15:50:13 +00:00
use App\Notifications\Channels\SendsEmail;
use Illuminate\Database\Eloquent\Casts\Attribute;
2023-03-28 13:47:37 +00:00
use Illuminate\Database\Eloquent\Model;
2023-06-06 15:50:13 +00:00
use Illuminate\Notifications\Notifiable;
2023-12-11 18:39:27 +00:00
use Illuminate\Support\Facades\Log;
2023-12-11 17:06:29 +00:00
use Illuminate\Support\Facades\Request;
use Spatie\Url\Url;
2023-03-28 13:47:37 +00:00
2023-06-06 15:50:13 +00:00
class InstanceSettings extends Model implements SendsEmail
2023-03-28 13:47:37 +00:00
{
use Notifiable;
2023-07-14 09:27:08 +00:00
protected $guarded = [];
2023-06-06 15:50:13 +00:00
protected $casts = [
2023-07-14 10:09:56 +00:00
'resale_license' => 'encrypted',
'smtp_password' => 'encrypted',
2023-06-06 15:50:13 +00:00
];
public function fqdn(): Attribute
{
return Attribute::make(
set: function ($value) {
if ($value) {
$url = Url::fromString($value);
$host = $url->getHost();
return $url->getScheme() . '://' . $host;
}
}
);
}
2023-12-11 18:16:17 +00:00
public static function realtimePort()
{
2023-12-11 17:06:29 +00:00
$envDefined = env('PUSHER_PORT');
if ($envDefined != '6001') {
return $envDefined;
}
$url = Url::fromString(Request::getSchemeAndHttpHost());
2023-12-11 18:39:27 +00:00
Log::info(Request::getSchemeAndHttpHost());
Log::info($url);
2023-12-11 18:30:37 +00:00
$scheme = $url->getScheme();
ray($url);
2023-12-11 18:02:06 +00:00
$port = $url->getPort();
if ($port) {
2023-12-11 18:36:44 +00:00
return '6001';
2023-12-11 17:06:29 +00:00
} else {
2023-12-11 18:16:17 +00:00
return null;
2023-12-11 17:06:29 +00:00
}
}
public static function get()
{
return InstanceSettings::findOrFail(0);
}
2023-07-28 08:55:26 +00:00
public function getRecepients($notification)
2023-06-06 15:50:13 +00:00
{
$recipients = data_get($notification, 'emails', null);
2023-06-06 15:50:13 +00:00
if (is_null($recipients) || $recipients === '') {
return [];
}
return explode(',', $recipients);
}
}