Error Handling
It’s good practice to handle potential errors, such as connection timeouts or invalid API credentials.
php
use Illuminate\Support\Facades\Log;
use Maidul\SearchJet\Exceptions\SearchJetException;
try {
$results = $searchJet->search($query)->paginate(10);
} catch (SearchJetException $e) {
// Log the error for debugging
Log::error('SearchJet search failed: ' . $e->getMessage());
// Return a user-friendly message
return back()->with('error', 'Sorry, the search is temporarily unavailable.');
}