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\Contracts\Database\Eloquent\Builder;
|
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;
|
|
|
|
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
|
2023-06-20 17:08:43 +00:00
|
|
|
use Spatie\SchemalessAttributes\SchemalessAttributesTrait;
|
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
|
|
|
{
|
2023-06-20 17:08:43 +00:00
|
|
|
use Notifiable, SchemalessAttributesTrait;
|
|
|
|
protected $schemalessAttributes = [
|
|
|
|
'smtp',
|
|
|
|
];
|
2023-06-06 15:50:13 +00:00
|
|
|
protected $casts = [
|
2023-06-20 17:08:43 +00:00
|
|
|
'smtp' => SchemalessAttributes::class,
|
2023-06-06 15:50:13 +00:00
|
|
|
];
|
2023-06-20 17:08:43 +00:00
|
|
|
public function scopeWithSmtp(): Builder
|
2023-06-06 15:50:13 +00:00
|
|
|
{
|
2023-06-20 17:08:43 +00:00
|
|
|
return $this->smtp->modelScope();
|
2023-06-06 15:50:13 +00:00
|
|
|
}
|
2023-06-20 17:08:43 +00:00
|
|
|
public function routeNotificationForEmail(string $attribute = 'test_recipients')
|
2023-06-06 15:50:13 +00:00
|
|
|
{
|
2023-06-20 17:08:43 +00:00
|
|
|
$recipients = $this->smtp->get($attribute, '');
|
2023-06-06 15:50:13 +00:00
|
|
|
if (is_null($recipients) || $recipients === '') {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return explode(',', $recipients);
|
|
|
|
}
|
2023-05-16 15:09:50 +00:00
|
|
|
public static function get()
|
|
|
|
{
|
|
|
|
return InstanceSettings::findOrFail(0);
|
|
|
|
}
|
2023-03-28 13:47:37 +00:00
|
|
|
}
|