PHPackages                             operation-gpt/operation-gpt - 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. operation-gpt/operation-gpt

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

operation-gpt/operation-gpt
===========================

AI-powered database operations via natural language

v1.0.3(2w ago)014MITPHPPHP ^8.1

Since Apr 8Pushed 3d agoCompare

[ Source](https://github.com/Ibrahimhassouna2022/OperationGpt)[ Packagist](https://packagist.org/packages/operation-gpt/operation-gpt)[ RSS](/packages/operation-gpt-operation-gpt/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (3)Dependencies (2)Versions (5)Used By (0)

OperationGPT
============

[](#operationgpt)

AI-powered database assistant for Laravel applications.

OperationGPT allows authenticated users to interact with application data using natural language while enforcing strict security, role-based permissions, and database whitelisting.

---

Features
--------

[](#features)

- Natural language database operations
- Role-based permissions
- Table &amp; column whitelisting
- OpenAI integration
- Secure password hashing
- Transaction-safe execution
- HTML report generation
- Customizable prompts per role
- Ready-to-use AI chat interface

---

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11+
- OpenAI API Key

---

Installation
============

[](#installation)

Install the package using Composer:

```
composer require operation-gpt/operation-gpt
```

Publish the package assets and configuration files:

```
php artisan vendor:publish --provider="OperationGpt\OperationGptServiceProvider"
```

After publishing, the following configuration files will be available:

```
config/
├── operation-gpt.php
└── operation-gpt-prompts.php

```

---

Configure OpenAI
================

[](#configure-openai)

Open your application's `.env` file:

```
OPENAI_API_KEY=your-api-key
OPERATION_GPT_MODEL=gpt-4o
```

### Purpose

[](#purpose)

- `OPENAI_API_KEY` authenticates requests to OpenAI.
- `OPERATION_GPT_MODEL` defines which model will be used.

---

Displaying the Chat Interface
=============================

[](#displaying-the-chat-interface)

After installation, the package provides a ready-to-use Blade view:

```
view('vendor.operation-gpt.chat')
```

You can display the AI chat interface using one of the following methods.

---

Option 1: Create a Dedicated Route
----------------------------------

[](#option-1-create-a-dedicated-route)

Open:

```
routes/web.php

```

Add:

```
Route::get('/ai-chat', function () {
    return view('vendor.operation-gpt.chat');
})->name('ai.chat');
```

Now visit:

```
http://your-domain.com/ai-chat

```

### Use this approach when:

[](#use-this-approach-when)

- You want a standalone AI assistant page.
- You want a dedicated URL for the chatbot.

---

Option 2: Include the Chat Inside an Existing Blade View
--------------------------------------------------------

[](#option-2-include-the-chat-inside-an-existing-blade-view)

You can embed the AI assistant inside any Blade page.

```
@include('vendor.operation-gpt.chat')
```

### Use this approach when:

[](#use-this-approach-when-1)

- You want the chatbot inside an existing dashboard.
- You want the assistant to appear beside other page content.

Examples:

- Teacher Dashboard
- Student Portal
- CRM Dashboard
- HR Management System

---

Option 3: Return the View from Your Own Controller
--------------------------------------------------

[](#option-3-return-the-view-from-your-own-controller)

```
class TeacherController extends Controller
{
    public function aiAssistant()
    {
        return view('vendor.operation-gpt.chat');
    }
}
```

Route:

```
Route::get('/teacher/assistant', [TeacherController::class, 'aiAssistant']);
```

### Use this approach when:

[](#use-this-approach-when-2)

- You need middleware protection.
- You need authorization checks.
- You need custom layouts.
- You need to pass additional data to the page.

---

Configure Allowed Tables
========================

[](#configure-allowed-tables)

Open:

```
config/operation-gpt.php

```

Example:

```
'allowed_tables' => [

    'users' => [
        'id',
        'name',
        'email',
        'role',
    ],

    'students' => [
        'id',
        'name',
        'gpa',
    ],

],
```

### Purpose

[](#purpose-1)

OperationGPT follows a whitelist security model.

Only the tables and columns defined here can be accessed by the AI.

Any table not listed here is automatically blocked.

---

Configure Roles &amp; Permissions
=================================

[](#configure-roles--permissions)

Open:

```
config/operation-gpt-prompts.php

```

Example:

```
'roles' => [

    'teacher' => [

        'name' => 'Teacher',

        'constraints' => [

            'allowed_operations' => [
                'SELECT',
                'UPDATE'
            ],

            'enforce_self_only' => false,

        ],

    ],

],
```

### Purpose

[](#purpose-2)

Defines what each role can do.

Example above:

✅ SELECT

✅ UPDATE

❌ INSERT

❌ DELETE

---

Configure AI Prompts
====================

[](#configure-ai-prompts)

All role prompts are located in:

```
config/operation-gpt-prompts.php

```

Example:

```
'teacher' => [

    'prompt' => "
        You are a Teacher Assistant.
        You can read all student records.
        You can update student GPA.
        You cannot delete records.
    ",

],
```

### Purpose

[](#purpose-3)

Prompts define how the AI behaves for each role.

You can create different behaviors for:

- Administrators
- Teachers
- Students
- Employees
- Managers

---

Configure Global Rules
======================

[](#configure-global-rules)

Inside:

```
config/operation-gpt-prompts.php

```

Locate:

```
'global_rules' => [

    "OUTPUT: JSON ONLY",

    "SCHEMA: :schema",

    "USER CONTEXT: :identifier",

],
```

### Purpose

[](#purpose-4)

These rules are automatically appended to every role prompt.

Use them to enforce:

- Output format
- Security requirements
- Global AI instructions
- System-wide restrictions

---

User Role Requirement
=====================

[](#user-role-requirement)

The package expects the authenticated user to have a role.

Example:

```
Auth::user()->role;
```

Recommended migration:

```
$table->string('role');
```

Example roles:

```
super_admin
teacher
student
user

```

If no role exists, the package automatically falls back to:

```
user

```

---

Example Usage
=============

[](#example-usage)

User:

```
Show all students with GPA greater than 90

```

User:

```
Update Ahmed's GPA to 95

```

User:

```
Create a new teacher named John

```

The AI converts the request into a structured operation, validates permissions, and executes the action safely.

---

Security
========

[](#security)

OperationGPT applies multiple layers of protection.

Table Whitelisting
------------------

[](#table-whitelisting)

Only configured tables can be accessed.

---

Operation Validation
--------------------

[](#operation-validation)

Each role can execute only its allowed operations.

---

Password Hashing
----------------

[](#password-hashing)

Passwords are automatically hashed using Laravel's Hash::make() before being stored.

---

Self Scope Enforcement
----------------------

[](#self-scope-enforcement)

Roles configured with:

```
'enforce_self_only' => true
```

can only access or modify their own records.

---

Transactions
------------

[](#transactions)

All write operations are executed inside database transactions.

Any failure automatically triggers a rollback.

---

Customization Guide
===================

[](#customization-guide)

Modify Allowed Tables
---------------------

[](#modify-allowed-tables)

File:

```
config/operation-gpt.php

```

Purpose:

Control which database tables and columns the AI can access.

---

Modify Roles &amp; Permissions
------------------------------

[](#modify-roles--permissions)

File:

```
config/operation-gpt-prompts.php

```

Purpose:

Define role restrictions and allowed operations.

---

Modify Role Prompts
-------------------

[](#modify-role-prompts)

File:

config/operation-gpt-prompts.php

Purpose:

Customize AI behavior for each role.

---

Modify Global Rules
-------------------

[](#modify-global-rules)

File:

```
config/operation-gpt-prompts.php

```

Purpose:

Apply instructions to every AI request.

---

Modify OpenAI Request Logic
---------------------------

[](#modify-openai-request-logic)

File:

```
src/Services/OpenAIService.php

```

Purpose:

Customize model requests, placeholders, and prompt generation.

---

Modify Query Execution Logic
----------------------------

[](#modify-query-execution-logic)

File:

```
src/Http/Controllers/ChatController.php

```

Purpose:

Customize validation, query execution, security checks, and report generation.

---

Modify Chat Interface
---------------------

[](#modify-chat-interface)

File:

```
resources/views/chat.blade.php

```

Purpose:

Customize the AI chat UI.

---

Workflow
========

[](#workflow)

```
User Request
      ↓
Role Detection
      ↓
Prompt Compilation
      ↓
OpenAI Response
      ↓
Permission Validation
      ↓
Database Transaction
      ↓
Result Formatting
      ↓
Response To User

```

---

License
=======

[](#license)

MIT License

Created with ❤️ for secure AI-powered database interactions in Laravel.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance99

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

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

Every ~16 days

Total

4

Last Release

14d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6b4cf3926fb3bb373ac798e0ac85514531826ceebcecf82c2d2ec2855c06bf48?d=identicon)[Ibrahimhassouna2022](/maintainers/Ibrahimhassouna2022)

---

Top Contributors

[![Ibrahimhassouna2022](https://avatars.githubusercontent.com/u/195318197?v=4)](https://github.com/Ibrahimhassouna2022 "Ibrahimhassouna2022 (25 commits)")[![AABMIS](https://avatars.githubusercontent.com/u/105827849?v=4)](https://github.com/AABMIS "AABMIS (10 commits)")[![Mohammed-Atef-Abu-Warda](https://avatars.githubusercontent.com/u/178516936?v=4)](https://github.com/Mohammed-Atef-Abu-Warda "Mohammed-Atef-Abu-Warda (2 commits)")

### Embed Badge

![Health badge](/badges/operation-gpt-operation-gpt/health.svg)

```
[![Health](https://phpackages.com/badges/operation-gpt-operation-gpt/health.svg)](https://phpackages.com/packages/operation-gpt-operation-gpt)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[illuminate/http

The Illuminate Http package.

13137.2M6.4k](/packages/illuminate-http)[spatie/laravel-export

Create a static site bundle from a Laravel app

670139.5k6](/packages/spatie-laravel-export)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1348.1k1](/packages/jasara-php-amzn-selling-partner-api)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1232.2k16](/packages/fleetbase-core-api)[lemaur/eloquent-publishing

207.8k1](/packages/lemaur-eloquent-publishing)

PHPackages © 2026

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