Day 5: Filtering AI Debugging Logs by Date and Keyword
In Day 4, we built a dashboard to view AI-powered Laravel debugger suggestions. Today, we’ll add filters for date and keyword search so you can easily find specific errors or suggestions from the AI debugger.
Step 1: Update Controller to Handle Filters
Edit AIDebugLogController.php
:
use Illuminate\Http\Request;
public function index(Request $request)
{
$query = AIDebugLog::query();
if ($request->filled('keyword')) {
$query->where('error_message', 'like', '%' . $request->keyword . '%')
->orWhere('ai_suggestion', 'like', '%' . $request->keyword . '%');
}
if ($request->filled('start_date')) {
$query->whereDate('created_at', '>=', $request->start_date);
}
if ($request->filled('end_date')) {
$query->whereDate('created_at', '<=', $request->end_date);
}
$logs = $query->latest()->paginate(20);
return view('ai-debugger.index', compact('logs'));
}
Step 2: Update the View with Filter Form
Edit resources/views/ai-debugger/index.blade.php
and insert this above the table:
<form method="GET" class="row g-3 mb-4">
<div class="col-md-3">
<input type="text" name="keyword" value="{{ request('keyword') }}" class="form-control" placeholder="Search keyword">
</div>
<div class="col-md-3">
<input type="date" name="start_date" value="{{ request('start_date') }}" class="form-control">
</div>
<div class="col-md-3">
<input type="date" name="end_date" value="{{ request('end_date') }}" class="form-control">
</div>
<div class="col-md-3">
<button type="submit" class="btn btn-primary">Filter</button>
<a href="{{ url('/ai-debugger') }}" class="btn btn-secondary">Reset</a>
</div>
</form>
The rest of the table below remains unchanged.
Step 3: Optional – Add Pagination Info
Below your table, improve UX with:
<p class="text-muted">Showing {{ $logs->firstItem() }} to {{ $logs->lastItem() }} of {{ $logs->total() }} results</p>
{{ $logs->appends(request()->query())->links() }}
Step 4: Test Filtering Features
- Visit:
http://127.0.0.1:8000/ai-debugger
- Search for keywords like
SQLSTATE
,Undefined variable
, orIntegrity constraint
. - Filter logs by date range using the date pickers.
Next Steps
In Day 6, we’ll implement tagging and categorization for AI debugging logs, allowing the system to classify errors (e.g., DB Error, Auth Error, Blade Error) automatically using GPT.