PHPackages                             zerexei/php-toolkit - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. zerexei/php-toolkit

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

zerexei/php-toolkit
===================

A collection of reusable Laravel &amp; PHP traits, helpers, and extensions

0.1.0(1mo ago)00MITPHP

Since Jul 8Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/zerexei/php-toolkit)[ Packagist](https://packagist.org/packages/zerexei/php-toolkit)[ RSS](/packages/zerexei-php-toolkit/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

Laravel &amp; PHP Toolkit
=========================

[](#laravel--php-toolkit)

 A collection of lightweight, modern, and highly reusable PHP traits, Eloquent helpers, and utility extensions.

 [![Latest Version on Packagist](https://camo.githubusercontent.com/85d2775766c8fdd469edad7be4137cb96c76dc700c194c6b067d0234376ff38f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a6572657865692f7068702d746f6f6c6b69742e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/85d2775766c8fdd469edad7be4137cb96c76dc700c194c6b067d0234376ff38f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a6572657865692f7068702d746f6f6c6b69742e7376673f7374796c653d666c61742d737175617265) [![Total Downloads](https://camo.githubusercontent.com/1b16ba0326c4af8d990a622767bd342f6e0fe1160ccff9b38521739c8165124c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a6572657865692f7068702d746f6f6c6b69742e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/1b16ba0326c4af8d990a622767bd342f6e0fe1160ccff9b38521739c8165124c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a6572657865692f7068702d746f6f6c6b69742e7376673f7374796c653d666c61742d737175617265) [![MIT License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265) [![PHP 8.2+](https://camo.githubusercontent.com/e165e38e31a9c99f58cf8c034b981119d63b6ecea34f71784c0740feb10fe457/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e322d3737376262342e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/e165e38e31a9c99f58cf8c034b981119d63b6ecea34f71784c0740feb10fe457/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e322d3737376262342e7376673f7374796c653d666c61742d737175617265) [![Laravel 12.x Components](https://camo.githubusercontent.com/75086ed59b15971e40e0cf9c5beb7eb857e770f0316836bccb8e53489f66920f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d2d636f6d706f6e656e74732d31322e782d7265642e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/75086ed59b15971e40e0cf9c5beb7eb857e770f0316836bccb8e53489f66920f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d2d636f6d706f6e656e74732d31322e782d7265642e7376673f7374796c653d666c61742d737175617265) [![PSR-4 Compliant](https://camo.githubusercontent.com/c82d054d22362479f1e362e5678985919020c31533e941fdd21749e7b743f64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d2d342d636f6d706c69616e742d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/c82d054d22362479f1e362e5678985919020c31533e941fdd21749e7b743f64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5053522d2d342d636f6d706c69616e742d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)

---

A minimal and efficient collection of PHP 8.2+ traits and utilities designed to enhance Eloquent models and PHP arrays/strings. Relies on specific, lightweight Illuminate components rather than the full Laravel framework.

Features
--------

[](#features)

- ⚡ **Cacheable** — Intuitive Eloquent instance caching API with custom TTLs and auto-generated keys.
- 📋 **HasActivityLogs** — Boilerplate-free Spatie Activitylog integration configured with smart defaults.
- 🔍 **Searchable** — Query-builder scope for full-text term searches matching prefixes.
- 🆔 **HasUuid** — Automatically generates secure UUIDs (v4) upon model creation.
- 🔗 **HasSlug** — Automatic generation of unique, collision-resistant slugs from a source field.
- 🚦 **HasStatus** — Status state management, validation checks, and query scoping.
- ⚙️ **HasFilters** — Flexible pipeline helper to filter query builders via closures or dedicated classes.
- 🧰 **StrHelper &amp; ArrHelper** — Context-rich utilities to manipulate strings and arrays cleanly.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Cacheable](#cacheable)
- [HasActivityLogs](#hasactivitylogs)
- [Searchable](#searchable)
- [HasUuid](#hasuuid)
- [HasSlug](#hasslug)
- [HasStatus](#hasstatus)
- [HasFilters](#hasfilters)
- [StrHelper](#strhelper)
- [ArrHelper](#arrhelper)
- [Requirements](#requirements)
- [License](#license)

---

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

[](#installation)

Require via Composer:

```
composer require zerexei/php-toolkit
```

---

Cacheable
---------

[](#cacheable)

Add instance caching to any Eloquent model. It dynamically generates cache keys based on model type, primary key, and the `updated_at` timestamp.

```
use Zerexei\PHPToolkit\Traits\Cacheable;

class Post extends Model
{
    use Cacheable;
}
```

```
// Check cache, retrieve, or store values
$post = Post::find(1);

if ($post->hasCache()) {
    $cachedData = $post->getCache();
}

$post->putCache('custom-serialized-data', 3600);
$post->forgetCache();
```

---

HasActivityLogs
---------------

[](#hasactivitylogs)

Integrate [Spatie's Laravel Activitylog](https://github.com/spatie/laravel-activitylog) with smart out-of-the-box settings (auto-headline model names, excludes sensitive fields, and logs request IPs).

```
use Zerexei\PHPToolkit\Traits\HasActivityLogs;

class User extends Model
{
    use HasActivityLogs;
}
```

---

Searchable
----------

[](#searchable)

Enable simple, multi-column search on your models using SQL `LIKE` conditions.

```
use Zerexei\PHPToolkit\Traits\Searchable;

class Product extends Model
{
    use Searchable;
}
```

```
// Query products matching "macbook pro" across title and description
$products = Product::search(['title', 'description'], 'macbook pro')->get();
```

---

HasUuid
-------

[](#hasuuid)

Instruct Eloquent to auto-generate and manage UUID keys (UUIDv4) on model creation.

```
use Zerexei\PHPToolkit\Traits\HasUuid;

class Invoice extends Model
{
    use HasUuid;
}
```

---

HasSlug
-------

[](#hasslug)

Automatically generate slugs on model saving. Handles slug collisions automatically by appending increments (e.g. `my-slug-1`).

```
use Zerexei\PHPToolkit\Traits\HasSlug;

class Article extends Model
{
    use HasSlug;

    // Optional overrides:
    public function slugSource(): string
    {
        return 'title'; // Source column (Default: 'title')
    }

    public function slugDestination(): string
    {
        return 'slug'; // Destination column (Default: 'slug')
    }
}
```

---

HasStatus
---------

[](#hasstatus)

Validate, mutate, and scope models by their status.

```
use Zerexei\PHPToolkit\Traits\HasStatus;

class Project extends Model
{
    use HasStatus;

    public function getStatuses(): array
    {
        return ['draft', 'active', 'completed', 'archived'];
    }
}
```

```
// Usage
$project->setStatus('active'); // Throws InvalidArgumentException if invalid
$project->isStatus('completed'); // false

// Scope queries
$activeProjects = Project::ofStatus('active')->get();
$filteredProjects = Project::ofStatus(['active', 'completed'])->get();
```

---

HasFilters
----------

[](#hasfilters)

Apply request-driven filters or query builder callbacks cleanly.

```
use Zerexei\PHPToolkit\Traits\HasFilters;

class Order extends Model
{
    use HasFilters;
}
```

```
// 1. Using a closure
$orders = Order::filter(function ($query) {
    $query->where('amount', '>', 100);
})->get();

// 2. Using a dedicated Filter Class (must implement an `apply` method)
$orders = Order::filter(\App\Filters\OrderFilter::class)->get();
```

---

StrHelper
---------

[](#strhelper)

Common string manipulations.

```
use Zerexei\PHPToolkit\Utilities\StrHelper;

// Get initials
StrHelper::initials('Taylor Otwell'); // "TO"

// Estimate reading time in minutes
StrHelper::readingTime($longText, $wordsPerMinute = 200); // 4

// Truncate to exact length while preserving word boundaries
StrHelper::truncateWords($text, $limit = 80);
```

---

ArrHelper
---------

[](#arrhelper)

Manipulate PHP arrays effortlessly.

```
use Zerexei\PHPToolkit\Utilities\ArrHelper;

// Group items by a key path (supports arrays & objects)
ArrHelper::groupByKey($users, 'role_id');

// Remove all null values recursively from nested arrays
ArrHelper::filterNullRecursive($dirtyArray);

// Safely rename associative array keys
ArrHelper::renameKeys($data, ['user_id' => 'id', 'user_email' => 'email']);
```

---

Requirements
------------

[](#requirements)

- **PHP**: `8.2` or higher
- **Laravel Components (`illuminate/database`, `illuminate/support`)**: `^12.0`
- **Composer**

---

License
-------

[](#license)

This project is open-source software licensed under the [MIT License](LICENSE).

###  Health Score

30

—

LowBetter than 61% of packages

Maintenance90

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity23

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

49d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/070bc396a58fbf36ba7a06bc98bf973867765f4f7e44ec093ff2fb3c63753101?d=identicon)[zerexei](/maintainers/zerexei)

---

Top Contributors

[![zerexei](https://avatars.githubusercontent.com/u/69749146?v=4)](https://github.com/zerexei "zerexei (14 commits)")

### Embed Badge

![Health badge](/badges/zerexei-php-toolkit/health.svg)

```
[![Health](https://phpackages.com/badges/zerexei-php-toolkit/health.svg)](https://phpackages.com/packages/zerexei-php-toolkit)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1239.7k25](/packages/fleetbase-core-api)[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[forjedio/inertia-table

Backend-driven dynamic tables for Laravel + Inertia.js

272.0k](/packages/forjedio-inertia-table)[aedart/athenaeum

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

265.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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