定制 sambenge/codeigniter4-sole 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sambenge/codeigniter4-sole

最新稳定版本:1.0.3

Composer 安装命令:

composer require sambenge/codeigniter4-sole

包简介

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

README 文档

README

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

From Packagist (recommended)

composer require sambenge/codeigniter4-sole

⚙️ 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()?

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.

统计信息

  • 总下载量: 54
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固