PHPackages                             sambenge/codeigniter4-sole - 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. sambenge/codeigniter4-sole

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

sambenge/codeigniter4-sole
==========================

Adds Laravel's sole() model method to CodeIgniter 4.

1.0.3(7mo ago)054MITPHPPHP &gt;=7.4

Since Oct 9Pushed 7mo agoCompare

[ Source](https://github.com/sambenge/codeigniter4-sole)[ Packagist](https://packagist.org/packages/sambenge/codeigniter4-sole)[ RSS](/packages/sambenge-codeigniter4-sole/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

CodeIgniter 4 Sole
==================

[](#codeigniter-4-sole)

A lightweight package that adds **Laravel-style `sole()`** behaviour to CodeIgniter 4 models.

> Ensures that a query returns **exactly one record**, otherwise throws an exception.

---

🚀 Installation
--------------

[](#-installation)

### From Packagist (recommended)

[](#from-packagist-recommended)

```
composer require sambenge/codeigniter4-sole
```

⚙️ Usage
--------

[](#️-usage)

In your model:

```
use CodeIgniter\Model;
use Bengey\Sole\SoleTrait;

class UserModel extends Model
{
    use SoleTrait;

    protected $table = 'users';
}
```

Then, in your service or controller:

```
$userModel = new UserModel();
try {
    $user = $userModel->where('email', 'john@smith.com')->sole();
    // Do something with $user
} catch (\Bengey\Sole\Exceptions\RecordNotFoundException $e) {
    // No records found
} catch (\Bengey\Sole\Exceptions\MultipleRecordsFoundException $e) {
    // More than one record found
}
```

🧠 Why use `sole()`?
-------------------

[](#-why-use-sole)

The `sole()` method is useful when you expect a query to return exactly one record. It helps to enforce this expectation by throwing exceptions if the result set is empty or contains multiple records. This can help to prevent bugs and ensure that your application behaves as expected.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance63

Regular maintenance activity

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

222d ago

### Community

Maintainers

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

---

Top Contributors

[![sambenge](https://avatars.githubusercontent.com/u/13433133?v=4)](https://github.com/sambenge "sambenge (6 commits)")

### Embed Badge

![Health badge](/badges/sambenge-codeigniter4-sole/health.svg)

```
[![Health](https://phpackages.com/badges/sambenge-codeigniter4-sole/health.svg)](https://phpackages.com/packages/sambenge-codeigniter4-sole)
```

###  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)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

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

Reliese Components for Laravel Framework code generation.

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

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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