Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PlatformInstance
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 channels
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 languages
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 findByUrl
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Models;
4
5use App\Enums\PlatformEnum;
6use Database\Factories\PlatformInstanceFactory;
7use Illuminate\Database\Eloquent\Factories\HasFactory;
8use Illuminate\Database\Eloquent\Model;
9use Illuminate\Database\Eloquent\Relations\BelongsToMany;
10use Illuminate\Database\Eloquent\Relations\HasMany;
11
12/**
13 * @method static updateOrCreate(array<string, mixed> $array, $instanceData)
14 * @method static where(string $string, mixed $operator)
15 * @property PlatformEnum $platform
16 * @property string $url
17 * @property string $name
18 * @property string $description
19 * @property boolean $is_active
20 */
21class PlatformInstance extends Model
22{
23    /** @use HasFactory<PlatformInstanceFactory> */
24    use HasFactory;
25    
26    protected $fillable = [
27        'platform',
28        'url',
29        'name',
30        'description',
31        'is_active'
32    ];
33
34    protected $casts = [
35        'platform' => PlatformEnum::class,
36        'is_active' => 'boolean'
37    ];
38
39    /**
40     * @return HasMany<PlatformChannel, $this>
41     */
42    public function channels(): HasMany
43    {
44        return $this->hasMany(PlatformChannel::class);
45    }
46
47    /**
48     * @return BelongsToMany<Language, $this>
49     */
50    public function languages(): BelongsToMany
51    {
52        return $this->belongsToMany(Language::class)
53            ->withPivot(['platform_language_id', 'is_default'])
54            ->withTimestamps();
55    }
56
57    public static function findByUrl(PlatformEnum $platform, string $url): ?self
58    {
59        return static::where('platform', $platform)
60            ->where('url', $url)
61            ->first();
62    }
63}