coolify/app/Models/Team.php

72 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace App\Models;
2023-06-01 12:15:33 +02:00
use App\Notifications\Channels\SendsEmail;
2023-05-25 18:27:52 +02: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-05-25 18:27:52 +02:00
use Notifiable;
protected $casts = [
2023-06-01 13:24:20 +02:00
'extra_attributes' => SchemalessAttributes::class,
'personal_team' => 'boolean',
];
protected $fillable = [
'id',
'name',
2023-05-25 18:27:52 +02:00
'personal_team',
2023-06-01 13:24:20 +02:00
'extra_attributes',
];
2023-05-25 18:27:52 +02:00
public function routeNotificationForDiscord()
{
2023-06-01 13:24:20 +02:00
return $this->extra_attributes->get('discord_webhook');
2023-05-25 18:27:52 +02:00
}
2023-06-06 17:50:13 +02:00
public function routeNotificationForEmail(string $attribute = 'smtp_recipients')
2023-05-25 18:27:52 +02:00
{
2023-06-01 13:24:20 +02:00
$recipients = $this->extra_attributes->get($attribute, '');
if (is_null($recipients) || $recipients === '') {
return [];
}
return explode(',', $recipients);
2023-05-25 18:27:52 +02:00
}
public function scopeWithExtraAttributes(): Builder
{
2023-06-01 13:24:20 +02:00
return $this->extra_attributes->modelScope();
2023-05-25 18:27:52 +02:00
}
public function projects()
{
return $this->hasMany(Project::class);
}
2023-05-25 18:27:52 +02:00
public function servers()
{
2023-03-27 14:31:42 +02:00
return $this->hasMany(Server::class);
}
2023-05-25 18:27:52 +02:00
public function applications()
{
2023-03-30 19:50:27 +02:00
return $this->hasManyThrough(Application::class, Project::class);
}
2023-05-25 18:27:52 +02:00
2023-05-03 12:38:57 +02:00
public function privateKeys()
{
return $this->hasMany(PrivateKey::class);
}
2023-06-02 12:34:45 +02:00
public function members()
{
2023-06-09 15:55:21 +02:00
return $this->belongsToMany(User::class, 'team_user', 'team_id', 'user_id')->withPivot('role');
}
public function invitations()
{
return $this->hasMany(TeamInvitation::class);
2023-06-02 12:34:45 +02:00
}
}