lasthourcloud/app/Models/InstanceSettings.php
Andras Bacsai 9f0ca1cc2e wip
2023-06-20 19:08:43 +02:00

38 lines
1.0 KiB
PHP

<?php
namespace App\Models;
use App\Notifications\Channels\SendsEmail;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
use Spatie\SchemalessAttributes\SchemalessAttributesTrait;
class InstanceSettings extends Model implements SendsEmail
{
use Notifiable, SchemalessAttributesTrait;
protected $schemalessAttributes = [
'smtp',
];
protected $casts = [
'smtp' => SchemalessAttributes::class,
];
public function scopeWithSmtp(): Builder
{
return $this->smtp->modelScope();
}
public function routeNotificationForEmail(string $attribute = 'test_recipients')
{
$recipients = $this->smtp->get($attribute, '');
if (is_null($recipients) || $recipients === '') {
return [];
}
return explode(',', $recipients);
}
public static function get()
{
return InstanceSettings::findOrFail(0);
}
}