PHPackages                             khalidmh/eloquent-sql - 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. khalidmh/eloquent-sql

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

khalidmh/eloquent-sql
=====================

A Laravel package for generating SQL insert statements from Eloquent model records.

1.1.1(1y ago)110MITPHPPHP ^7.3|^8.0

Since Dec 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/KhalidMh/eloquent-sql)[ Packagist](https://packagist.org/packages/khalidmh/eloquent-sql)[ RSS](/packages/khalidmh-eloquent-sql/feed)WikiDiscussions main Synced 1mo ago

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

EloquentSQL
===========

[](#eloquentsql)

EloquentSQL is a Laravel package that generates raw SQL insert queries from Eloquent model records. This package makes it easy to convert your Eloquent models into raw SQL insert statements, which can be useful for debugging, logging, exporting data, or batch insert operations.

🚀 Features
----------

[](#-features)

- Converts Eloquent model data into raw SQL insert statements
- Ability to exclude / include specific columns
- Easy to use with any Laravel Eloquent model
- Ideal for debugging, logging, or data migration

📦 Requirements
--------------

[](#-requirements)

- PHP 7.3 or higher
- Laravel 8.x or higher

🛠 Installation
--------------

[](#-installation)

You can install the package via Composer:

```
composer require khalidmh/eloquent-sql
```

📦 Usage
-------

[](#-usage)

### Generating Insert Query for a Model

[](#generating-insert-query-for-a-model)

```
use KhalidMh\EloquentSQL\EloquentSQL;
use App\Models\User;

$user = User::find(1);
$sql = EloquentSQL::set($user)->toQuery();

// Output: INSERT INTO `users` (`id`, `name`, `email`, ...) VALUES (1, 'John Doe', 'john@example.com', ...);
```

### Excluding Columns

[](#excluding-columns)

### Specify which columns to be excluded from the insert query

[](#specify-which-columns-to-be-excluded-from-the-insert-query)

```
use KhalidMh\EloquentSQL\EloquentSQL;
use App\Models\User;

$user = User::find(1);

$sql = EloquentSQL::set($user)
        ->except(['id', 'created_at', 'updated_at'])
        ->toQuery();

// Output: INSERT INTO `users` (`name`, `email`, ...) VALUES ('John Doe', 'john@example.com', ...);
```

### Including Columns

[](#including-columns)

### Specify which columns to be in the insert query

[](#specify-which-columns-to-be-in-the-insert-query)

```
use KhalidMh\EloquentSQL\EloquentSQL;
use App\Models\User;

$user = User::find(1);

$sql = EloquentSQL::set($user)
        ->only(['name', 'email'])
        ->toQuery();

// Output: INSERT INTO `users` (`name`, `email`) VALUES ('John Doe', 'johnjohn@example.com');
```

### Including hidden model attributes

[](#including-hidden-model-attributes)

### By default Laravel removes hidden attributes from the Model based on the $hidden property, you can use the includeHidden() to add them to the insert query without updating the Model's $hidden property globaly.

[](#by-default-laravel-removes-hidden-attributes-from-the-model-based-on-the-hidden-property-you-can-use-the-includehidden-to-add-them-to-the-insert-query-without-updating-the-models-hidden-property-globaly)

```
use KhalidMh\EloquentSQL\EloquentSQL;
use App\Models\User;

$user = User::find(1);

$sql = EloquentSQL::set($user)
        ->includeHidden()
        ->only(['password', 'remember_token'])
        ->toQuery();

// Output: INSERT INTO `users` (`password`, `remember_token`) VALUES ('password', '8zfuGf0f....');
```

⚙️ Configuration
----------------

[](#️-configuration)

No additional configuration is required. EloquentSQL works out-of-the-box with your existing Eloquent models.

📃 License
---------

[](#-license)

EloquentSQL is open-source software licensed under the [MIT license](LICENSE).

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please feel free to submit a pull request or open an issue.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

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

526d ago

### Community

Maintainers

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

---

Top Contributors

[![KhalidMh](https://avatars.githubusercontent.com/u/81515790?v=4)](https://github.com/KhalidMh "KhalidMh (53 commits)")

---

Tags

databaselaravelmysqlphplaravelgeneratorsqleloquentinsertstatement

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/khalidmh-eloquent-sql/health.svg)

```
[![Health](https://phpackages.com/badges/khalidmh-eloquent-sql/health.svg)](https://phpackages.com/packages/khalidmh-eloquent-sql)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[rennokki/laravel-eloquent-query-cache

Adding cache on your Laravel Eloquent queries' results is now a breeze.

1.1k4.0M14](/packages/rennokki-laravel-eloquent-query-cache)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)

PHPackages © 2026

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