33 lines
745 B
PHP
33 lines
745 B
PHP
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use App\Models\Feedback;
|
|
use App\Services\FileService;
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
class RequireProofOfResolution implements ValidationRule
|
|
{
|
|
protected Feedback $feedback;
|
|
|
|
public function __construct(Feedback $feedback)
|
|
{
|
|
$this->feedback = $feedback;
|
|
}
|
|
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
if ($value !== 'closed') {
|
|
return;
|
|
}
|
|
|
|
$fileService = App::make(FileService::class);
|
|
|
|
if (! $fileService->hasCollection($this->feedback, 'proof_of_resolution')) {
|
|
$fail(__('feedback.proof_required'));
|
|
}
|
|
}
|
|
}
|