Fixed api issue

This commit is contained in:
m.razaghi
2026-07-12 17:23:53 +03:30
parent dcea6423ff
commit aad67585ef

View File

@@ -175,7 +175,8 @@ class BylawApiController extends Controller
->orWhereIn('id', function($subQuery) use ($searchTerm) {
$subQuery->select('document_id')
->from('bylaw_nodes')
->where('node_content', 'LIKE', "%{$searchTerm}%");
->where('node_content', 'LIKE', "%{$searchTerm}%")
->orWhere('title', 'LIKE', "%{$searchTerm}%");
});
});
}
@@ -224,7 +225,8 @@ class BylawApiController extends Controller
->orWhereIn('id', function($subQuery) use ($searchTerm) {
$subQuery->select('document_id')
->from('bylaw_nodes')
->where('node_content', 'LIKE', "%{$searchTerm}%");
->where('node_content', 'LIKE', "%{$searchTerm}%")
->orWhere('title', 'LIKE', "%{$searchTerm}%");
});
});
}
@@ -310,18 +312,30 @@ class BylawApiController extends Controller
$description = $item->description;
// Check if description is practically empty (null, empty string, or just empty WYSIWYG HTML like <p></p>)
$cleanDesc = trim(strip_tags($description ?? ''));
// HARDCORE EMPTY CHECK: Destroy all tags, non-breaking spaces, and newlines.
$cleanDesc = trim(str_replace(['&nbsp;', '&zwnj;', "\r", "\n", "\t", ' '], '', strip_tags($description ?? '')));
// Direct Query Fallback: Fetch node_content manually via DB facade to bypass any Model restrictions
// If the description is genuinely empty, pull from the nodes table!
if (empty($cleanDesc)) {
$nodeContents = DB::table('bylaw_nodes')
$nodes = DB::table('bylaw_nodes')
->where('document_id', $item->id)
->orderBy('sort_order', 'asc')
->pluck('node_content')
->toArray();
->get(['title', 'node_content']); // Fetch BOTH title and node_content
$description = implode("\n\n", array_filter($nodeContents));
$descParts = [];
foreach ($nodes as $node) {
$nodeTitle = trim($node->title ?? '');
$nodeContent = trim($node->node_content ?? '');
if (!empty($nodeTitle)) {
$descParts[] = $nodeTitle;
}
if (!empty($nodeContent)) {
$descParts[] = $nodeContent;
}
}
$description = implode("\n\n", $descParts);
}
return [