lasthourcloud/app/Models/Team.php
Andras Bacsai 39d37010a3 fixes
2023-06-02 12:34:45 +02:00

68 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use App\Notifications\Channels\SendsEmail;
use App\Notifications\Channels\SendsDiscord;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Notifications\Notifiable;
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
class Team extends BaseModel implements SendsDiscord, SendsEmail
{
use Notifiable;
protected $casts = [
'extra_attributes' => SchemalessAttributes::class,
'personal_team' => 'boolean',
];
protected $fillable = [
'id',
'name',
'personal_team',
'extra_attributes',
];
public function routeNotificationForDiscord()
{
return $this->extra_attributes->get('discord_webhook');
}
public function routeNotificationForEmail(string $attribute = 'recipients')
{
$recipients = $this->extra_attributes->get($attribute, '');
if (is_null($recipients) || $recipients === '') {
return [];
}
return explode(',', $recipients);
}
public function scopeWithExtraAttributes(): Builder
{
return $this->extra_attributes->modelScope();
}
public function projects()
{
return $this->hasMany(Project::class);
}
public function servers()
{
return $this->hasMany(Server::class);
}
public function applications()
{
return $this->hasManyThrough(Application::class, Project::class);
}
public function privateKeys()
{
return $this->hasMany(PrivateKey::class);
}
public function members()
{
return $this->belongsToMany(User::class, 'team_user', 'team_id', 'user_id');
}
}