PHPackages                             kyle-noland/eloquent-foundation - 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. kyle-noland/eloquent-foundation

ActiveLibrary

kyle-noland/eloquent-foundation
===============================

A set of base classes for working with Laravel Eloquent Repositories, Models, Collections and Observers

1.0.3(11y ago)6147MITPHPPHP &gt;=5.4.0

Since May 12Pushed 11y ago1 watchersCompare

[ Source](https://github.com/kylenoland/eloquent-foundation)[ Packagist](https://packagist.org/packages/kyle-noland/eloquent-foundation)[ RSS](/packages/kyle-noland-eloquent-foundation/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (6)Used By (0)

Eloquent Foundation
===================

[](#eloquent-foundation)

The purpose of Eloquent Foundation is to provide a set of base classes for Laravel's Eloquent ORM that will speed development for most projects. You are free to use as many or as few of the Eloquent Foundation classes as you like.

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

[](#installation)

Install via Composer:

```
composer require kyle-noland/eloquent-foundation

```

Add the Service Provider to config/app.php

```
'providers' => [
    ...
    'KyleNoland\EloquentFoundation\Providers\EloquentFoundationServiceProvider',
]

```

Usage
-----

[](#usage)

Eloquent Foundation is opinionated and makes some assumptions regarding your database field names. For instance, the PersonTrait assumes that your Eloquent Model contains at least the following attributes:

- first\_name
- last\_name
- email

Most of the Eloquent Foundation classes are small. You should read through them to see how they work.

Probably the most generally useful components of Eloquent Foundation are the BaseRepositoryContract and BaseRepository classes. The intent is to provide an Eloquent repository implementation to build upon while maintaining some of the more common fluent Eloquent methods. *You get a lot of repository boilerplate for free and only have to write your application-specific methods in your child classes*.

For example, if you extend the BaseRepository class in your own InvoiceRepository class, you get a lot of good Eloquent methods "for free" while keeping direct access to your Eloquent models out of your controllers or service classes. You can do things like:

```
class SomeController extends Controller {

    protected $invoiceRepo;

    public function __construct(InvoiceRepositoryContract $invoiceRepo)
    {
        $this->invoiceRepo = $invoiceRepo;
    }

    public function something()
    {
        // Update a specific Invoice record
        $invoice = $this->invoiceRepo->updateById($id, $data);

        // Retrieve a specific Invoice record
        $invoice = $this->invoiceRepo->getById($id);

        // Retrieve all the Invoice records
        $invoices = $this->invoiceRepo->all();

        // Retrieve a Collection of Invoice records
        $invoices = $this->invoiceRepo->whereIn('id', [1, 2, 3, 10])->get();

        // Add the with() method to any "get-style" call to eager load related models
        $invoices = $this->invoiceRepo->with('Company', 'Company.Users')->whereIn('id', [1, 2, 99])->get();

        // Delete a particular Invoice record
        $this->invoiceRepo->deleteById($id);
    }

}

```

The BaseRepository class exposes the following boilerplate methods that you can leverage in any of your child classes:

```
/**
 * Get all the models
 *
 * @return \Illuminate\Database\Eloquent\Collection|static[]
 */
public function all();

/**
 * Count the specified models
 *
 * @return int
 */
public function count();

/**
 * Count the specified models
 *
 * @param $column
 * @param $value
 *
 * @return int
 */
public function countBy($column, $value);

/**
 * Create a new model
 *
 * @param array $data
 *
 * @return \Illuminate\Database\Eloquent\Model
 */
public function create(array $data);

/**
 * Create one or more new model records in the database
 *
 * @param array $data
 *
 * @return \Illuminate\Database\Eloquent\Collection
 */
public function createMultiple(array $data);

/**
 * Delete models
 *
 * @return mixed
 */
public function delete();

/**
 * Delete the specified model
 *
 * @param int $id
 *
 * @return int
 */
public function deleteById($id);

/**
 * Delete the specified models
 *
 * @param array $ids
 *
 * @return int
 */
public function deleteMultipleById(array $ids);

/**
 * Get the first specified model record from the database
 *
 * @return \Illuminate\Database\Eloquent\Model
 */
public function first();

/**
 * Get the first specified model record from the database
 *
 * @return \Illuminate\Database\Eloquent\Model
 */
public function firstOrFail();

/**
 * Get the specified models
 *
 * @return \Illuminate\Database\Eloquent\Collection|static[]
 */
public function get();

/**
 * Get the specified model
 *
 * @param int $id
 *
 * @return \Illuminate\Database\Eloquent\Model
 */
public function getById($id);

/**
 * Add a group by clause to the query
 *
 * @param $columns
 *
 * @return $this
 */
public function groupBy($columns);

/**
 * Add a limit clause to the query
 *
 * @param int $limit
 *
 * @return $this
 */
public function limit($limit);

/**
 * Add an order by clause to the query.
 *
 * @param  string  $column
 * @param  string  $direction
 * @return $this
 */
public function orderBy($column, $direction = 'asc');

/**
 * Update the specified model
 *
 * @param int   $id
 * @param array $data
 *
 * @return \Illuminate\Database\Eloquent\Model
 */
public function updateById($id, array $data);

/**
 * Add a basic where clause to the query.
 *
 * @param  string  $column
 * @param  string  $operator
 * @param  mixed   $value
 * @param  string  $boolean
 * @return $this
 */
public function where($column, $operator = null, $value = null, $boolean = 'and');

/**
 * Add a where in clause to the query
 *
 * @param        $column
 * @param        $values
 * @param string $boolean
 * @param bool   $not
 *
 * @return $this
 */
public function whereIn($column, $values, $boolean = 'and', $not = false);

/**
 * Add a where not in clause to the query
 *
 * @param        $column
 * @param        $values
 * @param string $boolean
 *
 * @return $this
 */
public function whereNotIn($column, $values, $boolean = 'and');

/**
 * Set relationships to eager load
 *
 * @param $relations
 *
 * @return $this
 */
public function with($relations);

```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

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

Total

4

Last Release

4018d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9cda1c5e60e743710eb8c2a39cb61da92d5193d1eba3f9adc5f7f9e3bb0bcc96?d=identicon)[KyleNoland](/maintainers/KyleNoland)

---

Top Contributors

[![kylenoland](https://avatars.githubusercontent.com/u/926626?v=4)](https://github.com/kylenoland "kylenoland (36 commits)")

### Embed Badge

![Health badge](/badges/kyle-noland-eloquent-foundation/health.svg)

```
[![Health](https://phpackages.com/badges/kyle-noland-eloquent-foundation/health.svg)](https://phpackages.com/packages/kyle-noland-eloquent-foundation)
```

###  Alternatives

[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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