-
app/Observers/SongObserver.php
Open in GitHubuse 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 GitHubuse 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); } }