diff --git a/app/Http/Controllers/api/BylawApiController.php b/app/Http/Controllers/api/BylawApiController.php index 3527c87..64f8bfb 100644 --- a/app/Http/Controllers/api/BylawApiController.php +++ b/app/Http/Controllers/api/BylawApiController.php @@ -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

) - $cleanDesc = trim(strip_tags($description ?? '')); + // HARDCORE EMPTY CHECK: Destroy all tags, non-breaking spaces, and newlines. + $cleanDesc = trim(str_replace([' ', '‌', "\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 [