Download the PHP package malsanyang/laravel-model-tools without Composer
On this page you can find all versions of the php package malsanyang/laravel-model-tools. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-model-tools
Laravel Model Tools
Laravel model utilities for applications that expose UUID references while keeping internal database IDs private.
Features
- Automatic UUID reference generation on model creation and update
reference()andreferenceOrFail()query helpers- Optional reference-based route model binding
- Migration generator for adding a reference column
- Optional
BaseModelwith soft deletes and datetime casts - Laravel package auto-discovery
Requirements
- PHP 8.3 or later
- Laravel 11, 12, or 13
Installation
Install the package with Composer:
Laravel discovers the package service provider automatically.
Publish the configuration file if you want to change the reference column or route model binding behaviour:
Usage
Add the HasReference trait to an Eloquent model:
Generate and run a migration for the model's table:
The generated migration adds the following column:
When a model is created or updated without a reference, the trait assigns a UUID automatically:
The trait checks that the configured column exists before assigning a UUID.
Finding Models by Reference
Return the matching model or null:
Return the matching model or throw an Eloquent ModelNotFoundException:
Configuration
The published config/model-tools.php file contains:
Custom Reference Column
Change reference_column to use a different column throughout the package:
The migration command uses the configured column by default. You can also override the generated migration's column explicitly:
Ensure the generated column name matches the column resolved by the model.
For a model-specific column, override the trait methods on that model:
Route Model Binding
Models using HasReference use the configured reference column for implicit
route model binding by default:
Given the default configuration, Laravel resolves {page} using the model's
reference value instead of its internal ID.
Disable this globally if you want Laravel to use the model's normal route key:
Optional Base Model
Applications that want shared defaults can extend the package base model:
Using the trait directly is recommended when you want more control over your model's behaviour.
Development
Install the development dependencies:
Run formatting checks, static analysis, and tests:
Run the complete CI suite, including Composer validation and the dependency security audit:
Individual checks are also available:
Security
Please report vulnerabilities privately by following the instructions in the security policy. Do not disclose security issues through public GitHub issues.
License
Laravel Model Tools is open-source software licensed under the MIT License.
All versions of laravel-model-tools with dependencies
illuminate/support Version ^11.0|^12.0|^13.0
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/console Version ^11.0|^12.0|^13.0