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

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

sebacarrasco93/laravel-ask-database
===================================

Use natural language and AI to query your database from Laravel

0171PHP

Since Mar 3Pushed 2y agoCompare

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

READMEChangelogDependenciesVersions (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/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)

Notes
-----

[](#notes)

> 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

> The original package created by [Beyond Code](https://github.com/beyondcode/laravel-ask-database) has been archived, also, it uses hardcoded text-davinci-003 model, and has been deprecated. However, this version supports custom specific models. You can change it into `config/ask-database.php` file, or into your `.env`

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

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

// We have 23 users with "pro" plan.
```

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

[](#installation)

Install the package via composer:

```
composer require sebacarrasco93/laravel-ask-database
```

Publish the config files with:

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

What about accidental deletions, updates or inserts? By default it's protecting by enabling strict mode. You can disable it. Do this at your own risk

```
// config/ask-database.php

'strict_mode' => env('ASK_DATABASE_STRICT_MODE', true),
```

Usage
-----

[](#usage)

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

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

By default it's using `gpt-3.5-turbo-instruct`. Optionally you can customize it

```
ASK_DATABASE_MODEL=gpt-3.5-turbo-instruct
```

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

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

// We have 100 users
```

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

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 Bus Factor1

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

### Community

Maintainers

![](https://www.gravatar.com/avatar/56bd71b023559779be29a38ac1c178f70c793bc5014ab9748799071e3421ba9a?d=identicon)[sebacarrasco93](/maintainers/sebacarrasco93)

---

Top Contributors

[![mpociot](https://avatars.githubusercontent.com/u/804684?v=4)](https://github.com/mpociot "mpociot (25 commits)")[![sebacarrasco93](https://avatars.githubusercontent.com/u/30738997?v=4)](https://github.com/sebacarrasco93 "sebacarrasco93 (11 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/sebacarrasco93-laravel-ask-database/health.svg)

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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