https://github.com/cleaniquecoders/traitify
Traitify is a Laravel package designed to streamline and enhance your development process by providing a collection of reusable traits and contracts.
https://github.com/cleaniquecoders/traitify
laravel php trait uuid
Last synced: 15 days ago
JSON representation
Traitify is a Laravel package designed to streamline and enhance your development process by providing a collection of reusable traits and contracts.
- Host: GitHub
- URL: https://github.com/cleaniquecoders/traitify
- Owner: cleaniquecoders
- License: mit
- Created: 2024-10-15T11:52:59.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-27T02:35:11.000Z (about 1 year ago)
- Last Synced: 2025-03-29T02:04:32.300Z (10 months ago)
- Topics: laravel, php, trait, uuid
- Language: PHP
- Homepage:
- Size: 44.9 KB
- Stars: 9
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# Traitify
[](https://packagist.org/packages/cleaniquecoders/traitify)
[](https://github.com/cleaniquecoders/traitify/actions?query=workflow%3Arun-tests+branch%3Amain)
[](https://github.com/cleaniquecoders/traitify/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[](https://packagist.org/packages/cleaniquecoders/traitify)
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
```bash
composer require cleaniquecoders/traitify
```
## ๐ Quick Start
```php
use CleaniqueCoders\Traitify\Concerns\InteractsWithUuid;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
use InteractsWithUuid;
// UUID automatically generated on creation
}
```
```php
$post = Post::create(['title' => 'Hello World']);
echo $post->uuid; // 9d9e8da7-78c3-4c9d-9f5e-5c8e4a2b1d3c
```
## ๐ Documentation
- **[Documentation Home](docs/README.md)** - Complete documentation index
- **[Getting Started](docs/01-getting-started/README.md)** - Installation and setup
- **[Architecture](docs/02-architecture/README.md)** - System design and patterns
- **[Traits Reference](docs/03-traits/README.md)** - All available traits
- **[Generators](docs/04-generators/README.md)** - Customizable value generation
- **[Configuration](docs/05-configuration/README.md)** - Configuration options
- **[Examples](docs/06-examples/README.md)** - Real-world usage examples
- **[Advanced](docs/07-advanced/README.md)** - Extend and customize
## ๐ฅ Popular Use Cases
### Auto-Generate UUIDs
```php
use InteractsWithUuid;
protected $uuid_column = 'id'; // Use UUID as primary key
```
### Secure API Tokens
```php
use InteractsWithToken;
protected $tokenGeneratorConfig = [
'length' => 64,
'prefix' => 'sk_',
'pool' => 'hex',
];
```
### SEO-Friendly Slugs
```php
use InteractsWithSlug;
protected $slugGeneratorConfig = [
'unique' => true,
'max_length' => 100,
];
```
## ๐งช Testing
```bash
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](CONTRIBUTING.md) for details.
## ๐ Security
If you discover any security issues, please review our [security policy](../../security/policy).
## ๐ Changelog
Please see [CHANGELOG](CHANGELOG.md) for recent changes.
## ๐ฅ Credits
- [Nasrul Hazim Bin Mohamad](https://github.com/nasrulhazim)
- [All Contributors](../../contributors)
## ๐ License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.