Migrate backend to Porto architecture and fix minor bugs

- Fully transitioned the backend to the Porto architectural pattern
- Improved code organization and maintainability
- Fixed minor bugs and inconsistencies
This commit is contained in:
F4ilji
2025-05-12 08:47:43 +05:00
parent 76deaf75f3
commit c01016a154
620 changed files with 16218 additions and 6073 deletions
@@ -0,0 +1,41 @@
<?php
namespace App\Containers\Widget\Data\Rules;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Facades\DB;
class UniqueJsonField implements Rule
{
protected int $formId;
protected string $fieldName;
public function __construct($formId, $fieldName)
{
$this->formId = $formId;
$this->fieldName = $fieldName;
}
public function passes($attribute, $value)
{
// Получаем все записи для данного custom_form_id
$responses = DB::table('custom_form_responses')
->where('custom_form_id', $this->formId)
->pluck('answers');
// Проверяем, есть ли значение в JSON
foreach ($responses as $response) {
$answers = json_decode($response, true);
if (isset($answers[$this->fieldName]) && $answers[$this->fieldName] === $value) {
return false; // Значение не уникально
}
}
return true; // Значение уникально
}
public function message()
{
return 'Поле должно быть уникальным';
}
}