3neti/laravel-model-input

A package to enable assigning inputs to Eloquent Models
1,088
Install
composer require 3neti/laravel-model-input
Latest Version:v1.2.0
PHP:^8.2
License:proprietary
Last Updated:Jul 31, 2026
Links: GitHub  ·  Packagist
Maintainer: 3neti

3neti/laravel-model-input

A Laravel package that enables dynamic, validated inputs attached to Eloquent models.

Features:

  • attach arbitrary named inputs to any model (polymorphic)
  • enforce validation rules per input type (via enum-driven rules)
  • normalize mobile numbers (via laravel-phone)
  • dynamic getters/setters via magic accessors
  • query models by input (e.g., find by mobile)
  • DTO support for structured responses

This package serves as a flexible input layer within the x-change ecosystem.


✨ Core Concept

Instead of adding many columns to a model, you can attach typed inputs:

  • mobile
  • email
  • signature
  • address
  • bank_account
  • etc.

Each input:

  • is stored in a separate inputs table
  • is validated using rules defined per input type
  • can be accessed like a normal attribute

📦 Installation

composer require 3neti/laravel-model-input:^1.2

The current release supports Laravel 12 and 13 on PHP 8.3 and 8.4.


⚙️ Configuration

Publish config (optional):

php artisan vendor:publish --tag=config

🧱 Database Migrations

This package uses:

loadMigrationsFrom()

Run:

php artisan migrate

🧠 Usage

Add trait to your model

use LBHurtado\ModelInput\Traits\HasInputs;

class User extends Model
{
    use HasInputs;
}

Set input

$user->setInput('mobile', '09171234567');

or using enum:

use LBHurtado\ModelInput\Enums\InputType;

$user->setInput(InputType::MOBILE, '09171234567');

Force set (skip validation)

$user->forceSetInput('mobile', '09171234567');

Access input like attribute

$user->mobile;
$user->signature;

Validate input

$user->isValidInput('email', 'test@example.com');

Query by input

User::findByMobile('09171234567');
User::findByInput('mobile', '09171234567');

Supports:

  • normalized matching
  • partial matching
  • flexible formats

Direct access

$user->input('mobile');

📱 Mobile Normalization

Mobile inputs are automatically normalized to:

E.164 format (without "+")

Examples:

  • 0917xxxxxxx
  • +63917xxxxxxx
  • 63917xxxxxxx

All resolve to the same stored value.


🧩 Input Types

Defined via enum:

InputType::MOBILE
InputType::EMAIL
InputType::SIGNATURE
InputType::OTP
...

Each input type has validation rules defined in config:

model-input.rules.mobile

🧾 Schema

inputs
- id
- model_type
- model_id
- name
- value
- timestamps

🧱 Traits

  • HasInputs → core functionality
  • dynamic getters/setters
  • validation and normalization

🧪 Testing

  • Testbench
  • SQLite in-memory
  • test-only migrations under tests/database/migrations

🧭 Architecture Role

In x-change ecosystem:

  • contact → identity
  • model-input → dynamic attributes layer
  • cash → value
  • voucher → instruction
  • wallet → ledger

🔒 Design Principles

  • avoid schema explosion
  • strongly typed inputs via enum
  • validation-first design
  • flexible querying
  • normalization of sensitive fields (e.g., mobile)

🚀 Future Enhancements

  • input history versioning
  • encryption support
  • indexing optimizations
  • event hooks

🧾 License

Proprietary

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

631,580,251 9,707
laravel/framework

The Laravel Framework.

580,311,802 34,925
laravel/tinker

Powerful REPL for the Laravel framework.

489,754,436 7,444
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

404,034,618 608
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

384,821,166 4,658