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.1.9(6mo ago)0201MITPHPPHP ^8.0

Since Apr 29Pushed 6mo 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 1mo ago

READMEChangelogDependencies (4)Versions (17)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

37

—

LowBetter than 83% of packages

Maintenance68

Regular maintenance activity

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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

Recently: every ~0 days

Total

15

Last Release

185d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6bf01d00c88c951fe9260577dcbb8d231138c16faf60d0c3d0d2b711ebc730e2?d=identicon)[ServiceTo](/maintainers/ServiceTo)

---

Top Contributors

[![ServiceTo](https://avatars.githubusercontent.com/u/4366064?v=4)](https://github.com/ServiceTo "ServiceTo (22 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

[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[genealabs/laravel-pivot-events

This package introduces new eloquent events for sync(), attach(), detach() or updateExistingPivot() methods on BelongsToMany relation.

1404.9M8](/packages/genealabs-laravel-pivot-events)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[aglipanci/laravel-eloquent-case

Adds CASE statement support to Laravel Query Builder.

115157.2k](/packages/aglipanci-laravel-eloquent-case)

PHPackages © 2026

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