2023-03-24 14:54:17 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2023-06-01 12:15:33 +02:00
|
|
|
use App\Notifications\Channels\SendsEmail;
|
2023-05-25 17:27:52 +01:00
|
|
|
use App\Notifications\Channels\SendsDiscord;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
|
|
|
|
|
2023-06-01 12:15:33 +02:00
|
|
|
class Team extends BaseModel implements SendsDiscord, SendsEmail
|
2023-03-24 14:54:17 +01:00
|
|
|
{
|
2023-05-25 17:27:52 +01:00
|
|
|
use Notifiable;
|
|
|
|
|
2023-03-24 14:54:17 +01:00
|
|
|
protected $casts = [
|
2023-06-01 12:15:33 +02:00
|
|
|
'smtp_attributes' => SchemalessAttributes::class,
|
2023-03-24 14:54:17 +01:00
|
|
|
'personal_team' => 'boolean',
|
|
|
|
];
|
|
|
|
protected $fillable = [
|
2023-04-14 12:54:29 +02:00
|
|
|
'id',
|
2023-03-24 14:54:17 +01:00
|
|
|
'name',
|
2023-05-25 17:27:52 +01:00
|
|
|
'personal_team',
|
2023-06-01 12:15:33 +02:00
|
|
|
'smtp_attributes',
|
2023-03-24 14:54:17 +01:00
|
|
|
];
|
2023-05-25 17:27:52 +01:00
|
|
|
|
|
|
|
public function routeNotificationForDiscord()
|
|
|
|
{
|
2023-06-01 12:15:33 +02:00
|
|
|
return $this->smtp_attributes->get('discord_webhook');
|
2023-05-25 17:27:52 +01:00
|
|
|
}
|
|
|
|
|
2023-06-01 12:15:33 +02:00
|
|
|
public function routeNotificationForEmail(string $attribute = 'recipients')
|
2023-05-25 17:27:52 +01:00
|
|
|
{
|
2023-06-01 12:15:33 +02:00
|
|
|
$recipients = $this->smtp_attributes->get($attribute, '');
|
2023-05-25 17:27:52 +01:00
|
|
|
return explode(PHP_EOL, $recipients);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeWithExtraAttributes(): Builder
|
|
|
|
{
|
2023-06-01 12:15:33 +02:00
|
|
|
return $this->smtp_attributes->modelScope();
|
2023-05-25 17:27:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-26 15:38:50 +02:00
|
|
|
public function projects()
|
|
|
|
{
|
2023-03-27 10:44:31 +02:00
|
|
|
return $this->hasMany(Project::class);
|
|
|
|
}
|
2023-05-25 17:27:52 +01:00
|
|
|
|
2023-04-26 15:38:50 +02:00
|
|
|
public function servers()
|
|
|
|
{
|
2023-03-27 14:31:42 +02:00
|
|
|
return $this->hasMany(Server::class);
|
|
|
|
}
|
2023-05-25 17:27:52 +01:00
|
|
|
|
2023-04-26 15:38:50 +02:00
|
|
|
public function applications()
|
|
|
|
{
|
2023-03-30 19:50:27 +02:00
|
|
|
return $this->hasManyThrough(Application::class, Project::class);
|
|
|
|
}
|
2023-05-25 17:27:52 +01:00
|
|
|
|
2023-05-03 12:38:57 +02:00
|
|
|
public function privateKeys()
|
|
|
|
{
|
|
|
|
return $this->hasMany(PrivateKey::class);
|
|
|
|
}
|
2023-03-24 14:54:17 +01:00
|
|
|
}
|