cleaniquecoders / traitify
Traitify is a Laravel package designed to streamline and enhance your development process by providing a collection of reusable traits and contracts.
Fund package maintenance!
Cleanique Coders
Installs: 4 520
Dependents: 15
Suggesters: 0
Security: 0
Stars: 18
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/cleaniquecoders/traitify
Requires
- php: ^8.2|^8.3|^8.4
- illuminate/contracts: ^10.0||^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9|^3.7
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.5|^10.0
- pestphp/pest: ^2.34|^3.0|4.0
- pestphp/pest-plugin-arch: ^2.7|^3.0|4.0
- pestphp/pest-plugin-laravel: ^2.3|^3.0|4.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1|^2.0
- phpstan/phpstan-phpunit: ^1.3|^2.0
README
A Laravel package that streamlines development with reusable traits, contracts, and a powerful value generator system. Reduce boilerplate, standardize behavior, and enhance your models with automatic UUID, token, and slug generation.
โจ Features
- ๐ง 11 Reusable Traits - UUID, Token, Slug, Meta, User, API, Search, and more
- ๐จ Customizable Generators - Flexible token, UUID, and slug generation
- โ๏ธ Three-Tier Configuration - Model โ Config โ Default resolution
- ๐ Extensible Architecture - Create custom generators easily
- ๐ฆ Zero Configuration - Works out of the box with sensible defaults
- โ 100% Tested - Comprehensive test coverage with Pest PHP
๐ฆ Installation
composer require cleaniquecoders/traitify
๐ Quick Start
use CleaniqueCoders\Traitify\Concerns\InteractsWithUuid; use Illuminate\Database\Eloquent\Model; class Post extends Model { use InteractsWithUuid; // UUID automatically generated on creation }
$post = Post::create(['title' => 'Hello World']); echo $post->uuid; // 9d9e8da7-78c3-4c9d-9f5e-5c8e4a2b1d3c
๐ Documentation
- Documentation Home - Complete documentation index
- Getting Started - Installation and setup
- Architecture - System design and patterns
- Traits Reference - All available traits
- Generators - Customizable value generation
- Configuration - Configuration options
- Examples - Real-world usage examples
- Advanced - Extend and customize
๐ฅ Popular Use Cases
Auto-Generate UUIDs
use InteractsWithUuid; protected $uuid_column = 'id'; // Use UUID as primary key
Secure API Tokens
use InteractsWithToken; protected $tokenGeneratorConfig = [ 'length' => 64, 'prefix' => 'sk_', 'pool' => 'hex', ];
SEO-Friendly Slugs
use InteractsWithSlug; protected $slugGeneratorConfig = [ 'unique' => true, 'max_length' => 100, ];
๐งช Testing
composer test
๐ Available Traits
| Trait | Purpose |
|---|---|
InteractsWithUuid |
Auto-generate UUIDs |
InteractsWithToken |
Generate secure tokens |
InteractsWithSlug |
Create URL-friendly slugs |
InteractsWithMeta |
Manage JSON metadata |
InteractsWithUser |
Auto-assign user relationships |
InteractsWithApi |
API response formatting |
InteractsWithSearchable |
Full-text search |
InteractsWithDetails |
Eager load relationships |
InteractsWithEnum |
Enum helper methods |
InteractsWithResourceRoute |
Resource route generation |
InteractsWithSqlViewMigration |
SQL view migrations |
๐ค Contributing
Contributions are welcome! Please see CONTRIBUTING for details.
๐ Security
If you discover any security issues, please review our security policy.
๐ Changelog
Please see CHANGELOG for recent changes.
๐ฅ Credits
๐ License
The MIT License (MIT). Please see License File for more information.