PHPackages                             legiaifenix/databasegate - 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. legiaifenix/databasegate

ActiveLibrary

legiaifenix/databasegate
========================

Laravel database manager to help make it more structural and visually logical to developers

0.1.9(9y ago)2108↓100%MITPHP

Since Jun 17Pushed 9y ago1 watchersCompare

[ Source](https://github.com/legiaifenix/DatabaseGate)[ Packagist](https://packagist.org/packages/legiaifenix/databasegate)[ RSS](/packages/legiaifenix-databasegate/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (14)Used By (0)

\#Legiai Fenix DatabaseGate

**Version:** 0.1.8 **Frameworks:** Laravel 5.\* **License:** MIT

**Supported functionality:** select, join, leftJoin, where, orWhere, whereBetween, group, sum, count, paginate, delete, update, insert

**Future Support:** PDO

This is a small package to help boost laravel development. Its objective is to simplify the use of database tables in order to minimize the written code and create a visual way to help developers understand the queries they are building. Through it they can call in any service/controller they desire and make use of the entire database with just one class.

You will be creating arrays with keys that will navigate through your DB and fetch the desire information

\##Instalation To start using the package, two steps are needed.

**1.** Require the package in CMD by running following command:

```
    composer require legiaifenix/databasegate

```

Or add it to your composer.json file in the "required" field:

```
    "require": {
            ...
            "legiaifenix/databasegate": "*"
        },

```

**2.** To start using it in your Controllers/Services/Classes just inject the class where you need it!

```
    public function reallyNeedToSortThis(DatabaseService $databaseService)
    {
        return $databaseService->getEntriesOfTableWithConditions($yourDesiredTable, $yourConditions);
    }

```

See below documentation to know how to access your table and sort your searches!

**Note:** The package now considers a SELECT when no order of the major logics is provided. For example, if oyu had joins, wheres and any other clause that does not fall in the category of major logic (SELECT, UPDATE, DELETE or INSERT) it will grab your conditions and execute a SELECT as default.

\##Geting total products in products table

```
    $conditions = [
        'count' => '*'
    ];

    $results = $databaseGate->getEntriesOfTableWithConditions('products', $conditions);

```

\##Getting products for each client

Lets assume you got the products in "products" table and clients in "clients" table;

```
    $conditions = [
        'select' => [
            ['clients.name'],
            ['clients.email'],
            ['products.*']
        ],
        'join' => [
            'products' => ['products.client_id', '=', 'clients.id']
        ]
    ];

    $results = $databaseGate->getEntriesOfTableWithConditions('clients', $conditions);

```

\##Left Joins

Thanks to Joao Cunha I was able to remember that LEft Joins are missing. So here goes a new implementation of it. They work exactly like right joins, but they are left. Mind blow. Left joins will fetch the conjunction regardless if there are values or not. While right joins will only fetch rows that do not miss in their search. We are not oblige to own rows every time we do a search, right?

Here we go:

```
    $conditions = [
            'select' => [
                ['clients.name'],
                ['clients.email'],
                ['products.*']
            ],
            'leftJoin' => [
                'products' => ['products.client_id', '=', 'clients.id']
            ]
        ];

        $results = $databaseGate->getEntriesOfTableWithConditions('clients', $conditions);

```

\##If you wish to paginate your queries by 5 per page

```
    $conditions = [
        ...
        'paginate' => '5'
    ];

    $results = $databaseGate->getEntriesOfTableWithConditions('clients', $conditions);

```

\##Fetching products only for clients named "Mark" and keep pagination for 15 per page

```
    $conditions = [
        'select' => [
            ['clients.name'],
            ['clients.email'],
            ['products.*']
        ],
        'join' => [
            'products' => ['products.client_id', '=', 'clients.id']
        ],
        'where' => [
            ['clients.name', 'LIKE', 'Mark%']
        ],
        'paginate' => '15'
    ];

    $results = $databaseGate->getEntriesOfTableWithConditions('clients', $conditions);

```

\##Getting all products that are visible

When you target only one table (what I like to consider the main table for all searches) you dont need to specify the select unless you just need a few columns from it. It depends of the value and columns you use for your logic.

```
    $conditions = [
        'where' => [
            ['products.visible', '=', '1']
        ]
    ];

    $results = $databaseGate->getEntriesOfTableWithConditions('products', $conditions);

```

\##Sum the cost of all products of the client with "" and get their email

We will be adding all the products price of the client with the "" email and name that column "totalCost" to use it in the views

```
    $conditions = [
        'select' => [
            ['clients.email'],
            ['( sum(products.price) )', 'totalCost']
        ],
        'join' => [
            'clients' => ['clients.id', '=', 'products.client_id']
        ],
        'where' => [
            ['clients.email', '=', 'example@email.com']
        ]
    ];

    $results = $databaseGate->getEntriesOfTableWithConditions('products', $conditions);

```

In the view we can use the object as:

```
    Client Email: {{$results->email}}
    Total Cost: {{$results->totalCost}}

```

\##Sum all that info!

If you wish just to have the cost you don't need to provide the select, you can deploy your array of conditions to just return the added value

```
    $conditions = [
            'join' => [
                'clients' => ['clients.id', '=', 'products.client_id']
            ],
            'where' => [
                ['clients.email', '=', 'example@email.com']
            ],
            'sum' => 'products.price'
        ];

    $results = $databaseGate->getEntriesOfTableWithConditions('products', $conditions);

```

\##Need prices between 30 and 70!

Well no problem, let us start by the example.

```
    $conditions = [
                'join' => [
                    'clients' => ['clients.id', '=', 'products.client_id']
                ],
                'where' => [
                    ['clients.email', '=', 'example@email.com']
                ],
                'whereBetween' => [
                    'price' => ['30', '70']
                ],
                'sum' => 'products.price'
            ];

        $results = $databaseGate->getEntriesOfTableWithConditions('products', $conditions);

```

Just like the Joins, you can add more arrays to specify even more where between clauses. The header that guides the arrays of values are, of course, the col names that own the comparison.

\##What about Having and its rainbow magic?!

Chill my friend, having is inserted, as well, to save the day!

Here is an example of how you can use it to save your day! It definitely saved mine!

```
    $conditions = [
                    'join' => [
                        'clients' => ['clients.id', '=', 'products.client_id']
                    ],
                    'where' => [
                        ['clients.email', '=', 'example@email.com']
                    ],
                    'having' => [
                        ["sum(orders.cost) = $value or sum(orders.q) = $value"]
                    ],
                    'sum' => 'products.price'
                ];

            $results = $databaseGate->getEntriesOfTableWithConditions('products', $conditions);

```

Yes you guess it well! It is only supporting a Raw Having query, but is not like it is so hard it broke your fellings, right? Anyhow I will be adding the queries outputs later on to help you debug them if needed or creating a deeper understanding of how does it exactly works.

\#Custom Pagination

You can implement your own target of rows through a custom pagination. Is not that different from pagination itself. All you have to do is substitute the single value by an array of 2 values, being them \[skip, amount\].

So, let us simulate we want 25 results corresponding to page 3:

```
    $conditions = [
            ...
            'pagination' = ['3', '25']
    ];

```

That is it! Enjoy your custom pagination methods! Of course try to implement the page and amount of results in a dynamic way, not static as this example. Damm who does this examples?

\##Debug my queries

V.0.1.3 included a debug for select queries. This are the ones that can get more complex and not totally straight forward. There for the necessity to debug them is immense. To start debugging them you can just add a true as boolean at the end of the calls.

Ex:. **Condition example**

```
                $conditions = [
                    'select' => [
                        ['colors.*']
                    ],
                    'order' => ['color_name', 'ASC']
                ];

```

```
    $results = $this->databaseGate->getEntriesOfTableWithConditions('colors', $conditions, true);
    var_dump($results);

```

**Output**

```
    select colors.* from `colors` order by `color_name` asc

```

**Debug example with joins**

```
            $conditions = [
                'select' => [
                    ['products_colors.*'],
                    ['colors.*']
                ],
                'joins' => [
                    'colors' => ['colors.id', '=', 'products_colors.color_id']
                ],
                'where' => [
                    ['colors.color_name', '=', 'test']
                ],
                'order' => ['color_name', 'ASC']
            ];

```

**Output**

```
    select products_colors.*,colors.* from `products_colors` where `colors`.`color_name` = ? order by `color_name` asc

```

\#Delete Query

if you wish to delete entries from your database, you sure know that Laravel provides that option and even more! For the time being I just allowed to delete permanently. Later intend to add the soft deletes.

**Condition example**

```
            $conditions = [
                'delete' => [
                    'permanent'
                ],
                'where' => [
                    ['col', '=', '']
                ]
            ];

```

The delete is already an array to accommodate the later changes which will have the soft deletes. For now use it as it is displayed.

\#Inserts

This insert will return the new id inserted in the database. So you can have an object or variable expecting it.

**Condition example**

```
            $conditions = [
                'insert' => [
                    'title' => 'test',
                    'price' => '33.33',
                    'other col here' => 'other value here'
                ]
            ];

```

```
    $id = $this->databaseGate->getEntriesOfTableWithConditions('', $conditions);
    var_dump($results);

```

\#Update Information

```
        $conditions = [
            'update' => [
                'title' => 'Title1',
                'desc' => 'description here'
            ],
            'where' => [
                ['title', '=', 'what I want to change']
            ]
        ];

        $this->databaseGate->getEntriesOfTableWithConditions('table name', $conditions);

```

###  Health Score

28

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~8 days

Total

13

Last Release

3470d ago

### Community

Maintainers

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

---

Top Contributors

[![legiaifenix](https://avatars.githubusercontent.com/u/19998610?v=4)](https://github.com/legiaifenix "legiaifenix (1 commits)")

### Embed Badge

![Health badge](/badges/legiaifenix-databasegate/health.svg)

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

PHPackages © 2026

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