PHPackages                             xtodx/laravel-ask-database - 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. [API Development](/categories/api)
4. /
5. xtodx/laravel-ask-database

ActiveLibrary[API Development](/categories/api)

xtodx/laravel-ask-database
==========================

Use natural language and AI to query your database from Laravel

01.8kPHP

Since Aug 10Pushed 9mo agoCompare

[ Source](https://github.com/xtodx/laravel-ask-database-fixed)[ Packagist](https://packagist.org/packages/xtodx/laravel-ask-database)[ RSS](/packages/xtodx-laravel-ask-database/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (1)Used By (0)

Laravel Ask DB: Natural Language Database Query Builder
=======================================================

[](#laravel-ask-db-natural-language-database-query-builder)

[![Latest Version on Packagist](https://camo.githubusercontent.com/526acecb275d101192d06497caeaecae36965d4aef8d29347a872f3a375bab18/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f78746f64782f6c61726176656c2d61736b2d64617461626173652d66697865642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/xtodx/laravel-ask-database-fixed)[![GitHub Tests Action Status](https://camo.githubusercontent.com/3bafceb43f1db5fbded3c1f2d681c965782fb9d77e1ef3e2a580466d841fcea8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f78746f64782f6c61726176656c2d61736b2d64617461626173652d66697865642f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/xtodx/laravel-ask-database-fixed/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/d722491684f2672faf01665056d010c616d0b189f60302330be63763fc3600dd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f78746f64782f6c61726176656c2d61736b2d64617461626173652d66697865642f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/xtodx/laravel-ask-database-fixed/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/9ab445816ab92d78c71d3da5f0a502a8487c3c75b3d991843576eb2996b7daef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f78746f64782f6c61726176656c2d61736b2d64617461626173652d66697865642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/xtodx/laravel-ask-database-fixed)

Note

This package is meant to be a learning resource for prompt engineering and how to achieve AI-generated query generation with PHP/Laravel. You should probably not use this in production

Ask DB allows you to use OpenAI's GPT-3 to build natural language database queries.

```
DB::ask('How many users do we have on the "pro" plan?');
```

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

[](#installation)

You can install the package via composer:

```
composer require xtodx/laravel-ask-database-fixed
```

You can publish the config file with:

```
php artisan vendor:publish --tag="ask-database-config"
```

This is the contents of the published config file:

```
return [
    /**
     * The database connection name to use. Depending on your
     * use case, you might want to limit the database user
     * to have read-only access to the database.
     */
    'connection' => env('ASK_DATABASE_DB_CONNECTION', 'mysql'),

    /**
     * Strict mode will throw an exception when the query
     * would perform a write/alter operation on the database.
     *
     * If you want to allow write operations - or if you are using a read-only
     * database user - you may disable strict mode.
     */
    'strict_mode' => env('ASK_DATABASE_STRICT_MODE', true),

    /**
     * The maximum number of tables to use before performing an additional
     * table name lookup call to OpenAI.
     * If you have a lot of database tables and columns, they might not fit
     * into a single request to OpenAI. In that case, we will perform a
     * lookup call to OpenAI to get the matching table names for the
     * provided question.
     */
    'max_tables_before_performing_lookup' => env('ASK_DATABASE_MAXIMUM_TABLES', 15),
];
```

Usage
-----

[](#usage)

First, you need to configure your OpenAI API key in your `.env` file:

```
OPENAI_API_KEY=sk-...
```

Then, you can use the `DB::ask()` method to ask the database:

```
$response = DB::ask('How many users are there?');
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Marcel Pociot](https://github.com/mpociot)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance41

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 Bus Factor1

Top contributor holds 78.1% 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/90301739899b418ac147020ef8fb09f1c8eea487e02f1bf1153bbade39564c6f?d=identicon)[xtodx](/maintainers/xtodx)

---

Top Contributors

[![mpociot](https://avatars.githubusercontent.com/u/804684?v=4)](https://github.com/mpociot "mpociot (25 commits)")[![tonykovalenkomb](https://avatars.githubusercontent.com/u/106664921?v=4)](https://github.com/tonykovalenkomb "tonykovalenkomb (4 commits)")[![anton-valii](https://avatars.githubusercontent.com/u/188476418?v=4)](https://github.com/anton-valii "anton-valii (1 commits)")[![hafezdivandari](https://avatars.githubusercontent.com/u/56585913?v=4)](https://github.com/hafezdivandari "hafezdivandari (1 commits)")[![tomlloyd](https://avatars.githubusercontent.com/u/51801753?v=4)](https://github.com/tomlloyd "tomlloyd (1 commits)")

### Embed Badge

![Health badge](/badges/xtodx-laravel-ask-database/health.svg)

```
[![Health](https://phpackages.com/badges/xtodx-laravel-ask-database/health.svg)](https://phpackages.com/packages/xtodx-laravel-ask-database)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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