Files
CRM/app/Services/Account/Photo/DestroyPhoto.php
Kroonk a213a1dba0
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
refactor: replace custom CRM with Monica fork
2026-05-22 16:19:55 +02:00

47 lines
1002 B
PHP

<?php
namespace App\Services\Account\Photo;
use App\Models\Account\Photo;
use App\Services\BaseService;
use Illuminate\Support\Facades\Storage;
class DestroyPhoto extends BaseService
{
/**
* Get the validation rules that apply to the service.
*
* @return array
*/
public function rules()
{
return [
'account_id' => 'required|integer|exists:accounts,id',
'photo_id' => 'required|integer|exists:photos,id',
];
}
/**
* Destroy a photo.
*
* @param array $data
* @return bool
*/
public function execute(array $data): bool
{
$this->validate($data);
$photo = Photo::where('account_id', $data['account_id'])
->findOrFail($data['photo_id']);
// Delete the physical photo
// Throws FileNotFoundException
Storage::delete($photo->new_filename);
// Delete the object in the DB
$photo->delete();
return true;
}
}