-
app/Enums/SourceType.php
Open in GitHubenum SourceType: string { case Youtube = 'youtube'; case Article = 'article'; case Podcast = 'podcast'; }
-
app/Models/Source.php
Open in GitHubuse App\Enums\SourceType; class Source extends Model { // ... protected function casts(): array { return [ 'is_tracked' => 'boolean', 'is_displayed' => 'boolean', 'type' => SourceType::class, 'last_checked_at' => 'datetime', ]; } }
-
app/Models/Material.php
Open in GitHubuse App\Enums\SourceType; use Illuminate\Contracts\Database\Eloquent\Builder; class Material extends Model { // ... public function scopeSourceType(Builder $query, SourceType $sourceType): void { $query->whereRelation('source', 'type', $sourceType); } public function isArticle(): bool { return $this->source->type === SourceType::Article; } public function isYoutube(): bool { return $this->source->type === SourceType::Youtube; } public function isPodcast(): bool { return $this->source->type === SourceType::Podcast; } // ... }