koel/app/Observers/SongObserver.php
2018-10-19 16:33:04 +02:00

26 lines
495 B
PHP

<?php
namespace App\Observers;
use App\Models\Song;
use App\Services\HelperService;
class SongObserver
{
private $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);
}
}