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

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

dotmarn/laravel-ask-database
============================

Use natural language and AI to query your database from Laravel

v2.0.0(7mo ago)118MITPHPPHP ^8.2

Since Apr 14Pushed 7mo agoCompare

[ Source](https://github.com/dotmarn/laravel-ask-database)[ Packagist](https://packagist.org/packages/dotmarn/laravel-ask-database)[ Docs](https://github.com/dotmarn/laravel-ask-database)[ RSS](/packages/dotmarn-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)

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

Publish the config files with:

```
php artisan vendor:publish --tag="ask-database-config"
php artisan vendor:publish --provider="OpenAI\Laravel\ServiceProvider"
```

This is the contents of the published config file:

```
return [
    /**
     * The OpenAI model to use:
     * "gpt-3.5-turbo-instruct" - The new default model.
     */
    'model' => env('ASK_DATABASE_MODEL', 'gpt-3.5-turbo-instruct'),
    /**
     * 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)

- [Ridwan Kasim](https://github.com/dotmarn)
- [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

Maintenance65

Regular maintenance activity

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75.8% 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 ~273 days

Total

3

Last Release

214d ago

Major Versions

v1.0.1 → v2.0.02025-10-12

PHP version history (2 changes)v1.0.0PHP ^8.1

v2.0.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18660010?v=4)[Ridwan Kasim](/maintainers/dotmarn)[@dotmarn](https://github.com/dotmarn)

---

Top Contributors

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

---

Tags

laravellaravel-ask-databasedotmarn

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[silber/bouncer

Eloquent roles and abilities.

3.6k4.4M25](/packages/silber-bouncer)[dyrynda/laravel-model-uuid

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

4802.8M8](/packages/dyrynda-laravel-model-uuid)[clickbar/laravel-magellan

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

423715.4k1](/packages/clickbar-laravel-magellan)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.1M11](/packages/bavix-laravel-wallet)[spatie/laravel-model-flags

Add flags to Eloquent models

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

PHPackages © 2026

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