PHPackages                             service-to/uses-detail - 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. service-to/uses-detail

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

service-to/uses-detail
======================

A Laravel trait for handling dynamic model attributes using a JSON detail column

v1.2.2(2mo ago)0251MITPHPPHP ^8.2

Since Apr 29Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/ServiceTo/UsesDetail)[ Packagist](https://packagist.org/packages/service-to/uses-detail)[ RSS](/packages/service-to-uses-detail/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (8)Versions (21)Used By (0)

UsesDetail
==========

[](#usesdetail)

A Laravel trait that enables dynamic model attributes using a JSON detail column.

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

[](#installation)

You can install the package via composer:

```
composer require service-to/uses-detail
```

Usage
-----

[](#usage)

1. Add the `detail` column to your migration:

```
Schema::create('your_table', function (Blueprint $table) {
    $table->id();
    $table->json('detail');
    $table->timestamps();
});
```

2. Use the trait in your model:

```
use ServiceTo\UsesDetail;

class YourModel extends Model
{
    use UsesDetail;
}
```

Features
--------

[](#features)

- **Smart Column Detection**: Automatically detects whether columns exist in the database schema or JSON detail column
- **Unified Query Interface**: Use standard Laravel query methods (`where`, `whereIn`, `whereNull`, etc.) for both schema and detail columns
- **Performance Optimized**: Schema information is cached for 5 minutes to minimize database lookups
- **Automatic UUID Generation**: Generates UUIDs for models automatically
- **Flexible Data Merging**: Merge objects or JSON strings into models
- **Fully Backward Compatible**: Existing `detail()` scope continues to work

Querying Data
-------------

[](#querying-data)

### Using Standard Laravel Query Methods (Recommended)

[](#using-standard-laravel-query-methods-recommended)

The package intelligently routes queries to either schema columns or the JSON detail column:

```
// Query any column - works automatically for both schema and detail columns
YourModel::where('name', 'John')->get();
YourModel::where('email', 'like', '%@example.com')->get();

// Use orWhere
YourModel::where('status', 'active')
         ->orWhere('priority', '>', 10)
         ->get();

// Use whereIn / whereNotIn
YourModel::whereIn('status', ['active', 'pending'])->get();
YourModel::whereNotIn('role', ['admin', 'superadmin'])->get();

// Use whereNull / whereNotNull
YourModel::whereNull('deleted_at')->get();
YourModel::whereNotNull('description')->get();

// Use whereBetween / whereNotBetween
YourModel::whereBetween('priority', [1, 10])->get();
YourModel::whereNotBetween('age', [18, 65])->get();

// Chain multiple conditions
YourModel::where('status', 'active')
         ->whereBetween('priority', [5, 15])
         ->whereNotNull('description')
         ->whereIn('category', ['A', 'B'])
         ->get();

// Use orderBy / orderByDesc
YourModel::orderBy('name')->get();
YourModel::orderByDesc('priority')->get();
YourModel::latest()->get();  // Orders by created_at desc
YourModel::oldest()->get();  // Orders by created_at asc

// Use groupBy with detail columns
YourModel::select('detail->category as category')
         ->selectRaw('COUNT(*) as count')
         ->groupBy('category')
         ->get();

// Group by multiple columns (mix schema and detail)
YourModel::select('status', 'detail->category as category')
         ->selectRaw('COUNT(*) as count')
         ->groupBy('status', 'category')
         ->get();

// Use having clause with groupBy
YourModel::select('detail->category as category')
         ->selectRaw('AVG(json_extract(detail, "$.priority")) as avg_priority')
         ->groupBy('category')
         ->having(\DB::raw('AVG(json_extract(detail, "$.priority"))'), '>', 5)
         ->get();

// Combine everything
YourModel::where('status', 'active')
         ->whereBetween('priority', [1, 10])
         ->groupBy('category')
         ->having(\DB::raw('COUNT(*)'), '>', 1)
         ->orderBy('category')
         ->get();
```

### Using the `detail()` Scope (Backward Compatible)

[](#using-the-detail-scope-backward-compatible)

The original `detail()` scope method still works:

```
YourModel::detail('custom_field', '=', 'value')->get();
YourModel::detail('status', 'active')->get();
```

**Note:** Both methods now use the same intelligent routing under the hood.

How It Works
------------

[](#how-it-works)

When you save a model, the trait automatically:

1. Checks which attributes exist in the database schema
2. Stores schema columns normally
3. Stores non-schema columns in the JSON `detail` column
4. Caches the schema information for 5 minutes

When you query, the custom query builder:

1. Checks the cached schema
2. Routes queries to regular columns if they exist in the schema
3. Routes queries to JSON paths (`detail->column`) if they don't exist in the schema

Methods
-------

[](#methods)

### `merge($obj)`

[](#mergeobj)

Merge an object, array, or JSON string into the model:

```
$model->merge($object);
$model->merge(['key' => 'value']);
$model->merge('{"key": "value"}');
```

### `find($id)`

[](#findid)

Enhanced find method with automatic UUID lookup:

```
// Find by primary key
$model = YourModel::find(1);

// Find by UUID (automatically detected if ID is 36 characters)
$model = YourModel::find('550e8400-e29b-41d4-a716-446655440000');
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance86

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

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

Recently: every ~40 days

Total

18

Last Release

71d ago

PHP version history (2 changes)1.0.0PHP ^8.0

v1.2.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4366064?v=4)[ServiceTo](/maintainers/ServiceTo)[@ServiceTo](https://github.com/ServiceTo)

---

Top Contributors

[![ServiceTo](https://avatars.githubusercontent.com/u/4366064?v=4)](https://github.com/ServiceTo "ServiceTo (27 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/service-to-uses-detail/health.svg)

```
[![Health](https://phpackages.com/badges/service-to-uses-detail/health.svg)](https://phpackages.com/packages/service-to-uses-detail)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[laravel-liberu/laravel-gedcom

A package that converts gedcom files to Eloquent models

782.5k1](/packages/laravel-liberu-laravel-gedcom)

PHPackages © 2026

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