2025-07-05 02:19:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use App\Enums\PlatformEnum;
|
2025-07-06 01:35:59 +02:00
|
|
|
use Database\Factories\PlatformInstanceFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2025-07-05 02:19:59 +02:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2025-07-05 18:26:04 +02:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
2025-07-05 02:19:59 +02:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
|
|
|
|
|
|
/**
|
2025-07-07 00:51:32 +02:00
|
|
|
* @method static updateOrCreate(array<string, mixed> $array, $instanceData)
|
2025-07-05 02:19:59 +02:00
|
|
|
* @method static where(string $string, mixed $operator)
|
|
|
|
|
* @property PlatformEnum $platform
|
|
|
|
|
* @property string $url
|
|
|
|
|
* @property string $name
|
|
|
|
|
* @property string $description
|
|
|
|
|
* @property boolean $is_active
|
|
|
|
|
*/
|
|
|
|
|
class PlatformInstance extends Model
|
|
|
|
|
{
|
2025-07-06 01:35:59 +02:00
|
|
|
/** @use HasFactory<PlatformInstanceFactory> */
|
|
|
|
|
use HasFactory;
|
|
|
|
|
|
2025-07-05 02:19:59 +02:00
|
|
|
protected $fillable = [
|
|
|
|
|
'platform',
|
|
|
|
|
'url',
|
|
|
|
|
'name',
|
|
|
|
|
'description',
|
|
|
|
|
'is_active'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'platform' => PlatformEnum::class,
|
|
|
|
|
'is_active' => 'boolean'
|
|
|
|
|
];
|
|
|
|
|
|
2025-07-07 00:51:32 +02:00
|
|
|
/**
|
|
|
|
|
* @return HasMany<PlatformChannel, $this>
|
|
|
|
|
*/
|
2025-07-05 18:26:04 +02:00
|
|
|
public function channels(): HasMany
|
2025-07-05 02:19:59 +02:00
|
|
|
{
|
2025-07-05 18:26:04 +02:00
|
|
|
return $this->hasMany(PlatformChannel::class);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-07 00:51:32 +02:00
|
|
|
/**
|
|
|
|
|
* @return BelongsToMany<Language, $this>
|
|
|
|
|
*/
|
2025-07-05 18:26:04 +02:00
|
|
|
public function languages(): BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Language::class)
|
|
|
|
|
->withPivot(['platform_language_id', 'is_default'])
|
|
|
|
|
->withTimestamps();
|
2025-07-05 02:19:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function findByUrl(PlatformEnum $platform, string $url): ?self
|
|
|
|
|
{
|
|
|
|
|
return static::where('platform', $platform)
|
|
|
|
|
->where('url', $url)
|
|
|
|
|
->first();
|
|
|
|
|
}
|
|
|
|
|
}
|