52 lines
1.3 KiB
PHP
52 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\PlatformEnum;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
/**
|
|
* @method static updateOrCreate(array $array, $instanceData)
|
|
* @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
|
|
{
|
|
protected $fillable = [
|
|
'platform',
|
|
'url',
|
|
'name',
|
|
'description',
|
|
'is_active'
|
|
];
|
|
|
|
protected $casts = [
|
|
'platform' => PlatformEnum::class,
|
|
'is_active' => 'boolean'
|
|
];
|
|
|
|
public function channels(): HasMany
|
|
{
|
|
return $this->hasMany(PlatformChannel::class);
|
|
}
|
|
|
|
public function languages(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Language::class)
|
|
->withPivot(['platform_language_id', 'is_default'])
|
|
->withTimestamps();
|
|
}
|
|
|
|
public static function findByUrl(PlatformEnum $platform, string $url): ?self
|
|
{
|
|
return static::where('platform', $platform)
|
|
->where('url', $url)
|
|
->first();
|
|
}
|
|
}
|