Fixed major bugs
This commit is contained in:
@@ -123,6 +123,34 @@ class BylawApiController extends Controller
|
||||
return $this->success($responseData, 'Success', 'Search Results Fetched');
|
||||
}
|
||||
|
||||
public function fast_search(Request $request)
|
||||
{
|
||||
$searchTerm = $request->input('search');
|
||||
|
||||
$query = BylawDocument::with(['category', 'approvalAuthority', 'promulgationAuthority'])
|
||||
->where('is_published', true);
|
||||
|
||||
if (!empty($searchTerm)) {
|
||||
$query->where(function ($q) use ($searchTerm) {
|
||||
$q->where('title', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhere('description', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhere('promulgation_number', 'LIKE', "%{$searchTerm}%")
|
||||
->orWhere('official_gazette_number', 'LIKE', "%{$searchTerm}%");
|
||||
});
|
||||
}
|
||||
|
||||
$count = $query->count();
|
||||
// Limit to 5 results for fast search dropdown
|
||||
$items = $query->orderBy('approval_date', 'desc')->take(5)->get()->map(function ($item) {
|
||||
return $this->formatBylaw($item);
|
||||
});
|
||||
|
||||
return $this->success([
|
||||
'items' => $items,
|
||||
'count' => $count
|
||||
], 'Success', 'Fast Search Results');
|
||||
}
|
||||
|
||||
public function pager($id)
|
||||
{
|
||||
$current = BylawDocument::with(['category', 'approvalAuthority', 'promulgationAuthority'])
|
||||
|
||||
Reference in New Issue
Block a user