Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

nabilhassen/larasense

62 stars
3 code files
View nabilhassen/larasense on GitHub

app/Enums/SourceType.php

Open in GitHub
enum SourceType: string
{
case Youtube = 'youtube';
case Article = 'article';
case Podcast = 'podcast';
}

app/Models/Source.php

Open in GitHub
use 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 GitHub
use 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;
}
 
// ...
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.