PHPackages                             xheaven/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. xheaven/laravel-ask-database

ActiveLibrary

xheaven/laravel-ask-database
============================

Use natural language and AI to query your database from Laravel

1.0.2(2y ago)01.7kMITPHPPHP ^8.1

Since Aug 31Pushed 2y agoCompare

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

READMEChangelog (3)Dependencies (16)Versions (4)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/f1f5f4fc2931171cc77252b614dfefedb05357d36140720b1cabb890837e09b5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6265796f6e64636f64652f6c61726176656c2d61736b2d64617461626173652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/beyondcode/laravel-ask-database)[![GitHub Tests Action Status](https://camo.githubusercontent.com/8738e48a0e2b3077f6f21a7862f81bfc0cf9e8a2f797b12e31175960c56175ce/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6265796f6e64636f64652f6c61726176656c2d61736b2d64617461626173652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/beyondcode/laravel-ask-database/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/0a57bb4c7675c018b6d4868b9cc9011b650fb12551daf3dd01a4ecf1343a5d1f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6265796f6e64636f64652f6c61726176656c2d61736b2d64617461626173652f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/beyondcode/laravel-ask-database/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/efc6b7a7d2cc50c2bc1adce9f80e53228143bad1f27f1778c7707c948d360641/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6265796f6e64636f64652f6c61726176656c2d61736b2d64617461626173652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/beyondcode/laravel-ask-database)

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 beyondcode/laravel-ask-database
```

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

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.5% 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.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

985d ago

### Community

Maintainers

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

---

Top Contributors

[![mpociot](https://avatars.githubusercontent.com/u/804684?v=4)](https://github.com/mpociot "mpociot (22 commits)")[![xHeaven](https://avatars.githubusercontent.com/u/14284867?v=4)](https://github.com/xHeaven "xHeaven (4 commits)")[![tomlloyd](https://avatars.githubusercontent.com/u/51801753?v=4)](https://github.com/tomlloyd "tomlloyd (1 commits)")

---

Tags

laravelbeyondcodelaravel-ask-database

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-onboard

A Laravel package to help track user onboarding steps

808342.9k1](/packages/spatie-laravel-onboard)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[spatie/laravel-prometheus

Export Laravel metrics to Prometheus

2651.3M6](/packages/spatie-laravel-prometheus)[giacomomasseron/laravel-models-generator

Generate Laravel models from an existing database

484.2k](/packages/giacomomasseron-laravel-models-generator)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[basillangevin/laravel-data-json-schemas

Transforms Spatie Data objects into JSON Schemas with built-in validation

1312.2k1](/packages/basillangevin-laravel-data-json-schemas)

PHPackages © 2026

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