koel/app/Observers/AlbumObserver.php

31 lines
498 B
PHP
Raw Normal View History

2018-08-29 07:58:46 +00:00
<?php
namespace App\Observers;
use App\Models\Album;
use Exception;
2018-08-31 13:47:15 +00:00
use Illuminate\Log\Logger;
2018-08-29 07:58:46 +00:00
class AlbumObserver
{
2018-08-31 13:47:15 +00:00
private $logger;
public function __construct(Logger $logger)
{
$this->logger = $logger;
}
2018-08-29 07:58:46 +00:00
public function deleted(Album $album): void
{
if (!$album->has_cover) {
return;
}
try {
unlink($album->cover_path);
} catch (Exception $e) {
2018-08-31 13:47:15 +00:00
$this->logger->error($e);
2018-08-29 07:58:46 +00:00
}
}
}