PHPackages                             coderubix/laravel-gemini-search - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. coderubix/laravel-gemini-search

ActiveLibrary[Search &amp; Filtering](/categories/search)

coderubix/laravel-gemini-search
===============================

AI-powered natural language database search using Google Gemini in Laravel.

19PHPCI failing

Since Aug 29Pushed 8mo agoCompare

[ Source](https://github.com/developer-ashok/laravel-gemini-search)[ Packagist](https://packagist.org/packages/coderubix/laravel-gemini-search)[ RSS](/packages/coderubix-laravel-gemini-search/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Gemini Search
=====================

[](#laravel-gemini-search)

AI-powered natural language database search using Google Gemini in Laravel with **multi-query support** and **intelligent result descriptions**.

Requirements
------------

[](#requirements)

- **PHP**: ^8.2
- **Laravel**: ^11.0
- **Google Gemini API**: Active API key

Dependencies
------------

[](#dependencies)

This package automatically includes the Google Gemini API PHP client as a dependency. **No manual installation required!**

When you install our package, Composer will automatically install:

- `coderubix/laravel-gemini-search` (our package)
- `google-gemini-php/client` (Google Gemini API client)
- All required dependencies

Installation
------------

[](#installation)

Simply install our package:

```
composer require coderubix/laravel-gemini-search
```

**That's it!** All dependencies are automatically resolved.

### Publish Configuration

[](#publish-configuration)

```
php artisan vendor:publish --tag=gemini-search-config
```

### Add API Key

[](#add-api-key)

Add your Gemini API key to your `.env` file:

```
GEMINI_API_KEY=your-api-key-here
```

Usage
-----

[](#usage)

### Basic Search

[](#basic-search)

```
use Coderubix\GeminiSearch\Facades\GeminiSearch;

$results = GeminiSearch::runSearch("Find all active users and count total orders");
```

### Service Injection

[](#service-injection)

```
use Coderubix\GeminiSearch\Services\GeminiSearchService;

class UserController extends Controller
{
    public function search(Request $request, GeminiSearchService $searchService)
    {
        $results = $searchService->runSearch($request->input('query'));
        return response()->json($results);
    }
}
```

API Endpoint
------------

[](#api-endpoint)

The package automatically registers a route at `/api/search`:

```
POST /api/search
{
    "query": "Find users who registered this month and count their orders"
}
```

Configuration
-------------

[](#configuration)

You can customize these settings in your `.env` file:

```
GEMINI_API_KEY=your-api-key
GEMINI_MODEL=gemini-1.5-flash
GEMINI_MAX_TOKENS=1000
GEMINI_TEMPERATURE=0.1
```

Features
--------

[](#features)

- **Natural Language Processing**: Convert plain English to SQL queries
- **AI-Powered**: Uses Google Gemini 1.5 Flash model for intelligent query generation
- **Multi-Query Support**: Handles complex requests with multiple SQL queries
- **Performance Optimized**: Automatically limits to 5 queries for optimal speed
- **SQL Injection Protection**: Only allows SELECT queries with built-in validation
- **Smart Descriptions**: AI-generated descriptions for each result (SQL hidden from users)
- **Auto-suggestions**: Generates related search suggestions
- **Schema Awareness**: Automatically detects and uses your database structure
- **Structured Responses**: Clean, professional JSON output format

Response Format
---------------

[](#response-format)

The package now returns structured JSON responses with AI-generated descriptions:

```
{
  "summary": "Processed 3 queries for user and order information",
  "performance_note": "Limited to 5 queries for optimal speed",
  "results": [
    {
      "description": "Count of total users in the system",
      "data": [{"count": 150}],
      "type": "count",
      "safe": true
    },
    {
      "description": "List of active users with registration dates",
      "data": [{"id": 1, "name": "John Doe", "active": true}],
      "type": "select",
      "safe": true
    }
  ],
  "suggestions": [
    "Show users with recent orders",
    "Find inactive users",
    "List users by order count"
  ],
  "total_queries_processed": 2,
  "queries_ignored": 0,
  "all_safe": true
}
```

### Key Benefits:

[](#key-benefits)

✅ **SQL Queries Hidden**: End users never see actual SQL syntax ✅ **AI Descriptions**: Natural language explanations of each result ✅ **Multi-Query Support**: Handle complex requests efficiently ✅ **Performance Control**: 5-query limit ensures optimal speed ✅ **Professional Output**: Clean, structured JSON responses

Testing
-------

[](#testing)

### Package Testing

[](#package-testing)

Run the test suite:

```
composer test
```

Or with PHPUnit directly:

```
./vendor/bin/phpunit
```

### Local Testing

[](#local-testing)

For development and testing, you can use our enhanced test script:

```
# Install dependencies
composer require google-gemini-php/client

# Create .env with your API key
echo "GEMINI_API_KEY=your-real-api-key" > .env

# Run comprehensive tests including multi-query functionality
php test-package.php
```

Security
--------

[](#security)

The package includes built-in SQL injection protection by:

- Only allowing SELECT queries
- Validating query types before execution
- Using parameterized queries where possible
- AI prompt optimization for clean SQL output
- Multi-query validation and safety checks

Performance
-----------

[](#performance)

- **Query Limit**: Maximum 5 queries per request for optimal performance
- **Smart Parsing**: Efficient query parsing and validation
- **Error Handling**: Graceful handling of failed queries
- **Performance Notes**: Automatic warnings when limits are reached
- **Configurable Limit**: Set via `MAX_QUERIES` constant in service class

Troubleshooting
---------------

[](#troubleshooting)

### Common Issues

[](#common-issues)

1. **"Class Gemini\\Client not found"**: The package will automatically install `google-gemini-php/client`
2. **"Invalid API key"**: Verify your `GEMINI_API_KEY` in `.env` (no quotes needed)
3. **"Unsafe query generated"**: The AI generated a non-SELECT query (safety feature)
4. **"Target class \[config\] does not exist"**: This is normal in standalone testing, will work in Laravel
5. **Multiple queries ignored**: Performance optimization limits to 5 queries (check performance\_note)

### Debug Mode

[](#debug-mode)

Enable debug mode in your `.env`:

```
APP_DEBUG=true
```

---

📞 Contact Information
---------------------

[](#-contact-information)

**Developer:** Ashok Chandrapal 👨‍💻
**Phone:** +91 9033359874 📱
**Email:**  ✉️
**GitHub:** [github.com/developer-ashok](https://github.com/developer-ashok) 🐙
**LinkedIn:** [linkedin.com/in/ashok-chandrapal](https://linkedin.com/in/ashok-chandrapal) 💼

---

Contributing
------------

[](#contributing)

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests for new functionality
5. Submit a pull request

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance42

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/f85d0845de47be3aaaf3709a8a14fae33c16d9685a3f85eec5aae0fbedaf69ba?d=identicon)[coderubix](/maintainers/coderubix)

---

Top Contributors

[![developer-ashok](https://avatars.githubusercontent.com/u/14976868?v=4)](https://github.com/developer-ashok "developer-ashok (16 commits)")

### Embed Badge

![Health badge](/badges/coderubix-laravel-gemini-search/health.svg)

```
[![Health](https://phpackages.com/badges/coderubix-laravel-gemini-search/health.svg)](https://phpackages.com/packages/coderubix-laravel-gemini-search)
```

###  Alternatives

[ruflin/elastica

Elasticsearch Client

2.3k50.4M203](/packages/ruflin-elastica)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15024.3M65](/packages/opensearch-project-opensearch-php)[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[massive/search-bundle

Massive Search Bundle

721.4M13](/packages/massive-search-bundle)[shyim/opensearch-php-dsl

OpenSearch/Elasticsearch DSL library

175.9M9](/packages/shyim-opensearch-php-dsl)[outl1ne/nova-multiselect-filter

Multiselect filter for Laravel Nova.

45802.7k3](/packages/outl1ne-nova-multiselect-filter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
