Skip to main content

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

Read more here

koel/koel

16858 stars
2 code files
View koel/koel on GitHub

app/Observers/SongObserver.php

Open in GitHub
use App\Models\Song;
use App\Services\HelperService;
 
class SongObserver
{
private HelperService $helperService;
 
public function __construct(HelperService $helperService)
{
$this->helperService = $helperService;
}
 
public function creating(Song $song): void
{
$this->setFileHashAsId($song);
}
 
private function setFileHashAsId(Song $song): void
{
$song->id = $this->helperService->getFileHash($song->path);
}
}

app/Providers/EventServiceProvider.php

Open in GitHub
use App\Models\Album;
use App\Models\Song;
use App\Observers\AlbumObserver;
use App\Observers\SongObserver;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
 
class EventServiceProvider extends ServiceProvider
{
//
public function boot(): void
{
parent::boot();
 
Song::observe(SongObserver::class);
Album::observe(AlbumObserver::class);
}
}

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.