PHPackages                             beyondcode/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. [Database &amp; ORM](/categories/database)
4. /
5. beyondcode/laravel-ask-database

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

beyondcode/laravel-ask-database
===============================

Use natural language and AI to query your database from Laravel

1.0.0(3y ago)2769.3k47MITPHPPHP ^8.1

Since Feb 21Pushed 2y ago6 watchersCompare

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

READMEChangelog (1)Dependencies (16)Versions (2)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)

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 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

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

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

Unknown

Total

1

Last Release

1182d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/863e91ca13b8c4031f202c0eee4f06b3a4352f92cf9cd397b03609b20247ed16?d=identicon)[beyondcode](/maintainers/beyondcode)

---

Top Contributors

[![mpociot](https://avatars.githubusercontent.com/u/804684?v=4)](https://github.com/mpociot "mpociot (25 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)")

---

Tags

aigpt-3laravelopenailaravelbeyondcodelaravel-ask-database

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8425.3M87](/packages/laravel-doctrine-orm)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spatie/laravel-model-flags

Add flags to Eloquent models

4301.1M1](/packages/spatie-laravel-model-flags)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[spatie/laravel-sql-commenter

Add comments to SQL queries made by Laravel

1931.4M1](/packages/spatie-laravel-sql-commenter)[spatie/laravel-deleted-models

Automatically copy deleted records to a separate table

409109.8k4](/packages/spatie-laravel-deleted-models)

PHPackages © 2026

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