Download the PHP package masum/laravel-tagging without Composer
On this page you can find all versions of the php package masum/laravel-tagging. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download masum/laravel-tagging
More information about masum/laravel-tagging
Files in masum/laravel-tagging
Package laravel-tagging
Short Description A comprehensive Laravel package for automatic tag generation and management with barcode support, events, bulk operations, and performance optimizations
License MIT
Homepage https://github.com/MasumNishat/laravel-tagging
Informations about the package laravel-tagging
Laravel Tagging
A comprehensive Laravel package for automatic tag generation and management with barcode support, events, and performance optimizations.
Overview
Laravel Tagging is a powerful, production-ready package that provides automatic tag generation and management for any Eloquent model. Perfect for inventory systems, asset tracking, equipment management, and any application requiring unique identifiers with barcode support.
Why Laravel Tagging?
- 🏷️ Automatic Tag Generation - Tags are generated automatically when models are created
- 🔢 Multiple Formats - Sequential (
EQ-001), Random (EQ-1698765432), Branch-based (SW-001-5) - 📊 Barcode Support - Generate CODE_128, QR codes, and more formats for physical labels
- 🖨️ Print Labels - Print-ready barcode labels for batch printing
- ⚡ High Performance - Race condition protection, caching, query optimization
- 🔔 Event System - Hook into tag operations for webhooks, audit trails, notifications
- 🔄 Bulk Operations - Regenerate or delete multiple tags efficiently
- 🛡️ Production Ready - Comprehensive tests, security hardening, error handling
- 📱 RESTful API - Complete API for frontend/mobile integration
- 🎨 Polymorphic - Tag any Eloquent model with a single trait
Table of Contents
- Requirements
- Installation
- Quick Start
- Testing with Tinker
- Features
- Tag Generation Formats
- Barcode Generation
- Events & Webhooks
- Bulk Operations
- RESTful API
- Configuration
- Usage
- Basic Usage
- Advanced Features
- API Integration
- Performance
- Security
- Testing
- Documentation
- Troubleshooting
- Changelog
- Contributing
- Credits
- License
Requirements
- PHP: 8.1, 8.2, or 8.3
- Laravel: 10.x, 11.x, or 12.x
- Database: MySQL 5.7+, PostgreSQL 10+, SQLite 3.8+, SQL Server 2017+
Installation
Install the package via Composer:
Publish and run migrations:
Optional: Publish the configuration file:
Quick Start
1. Add the Trait to Your Model
2. Create a Tag Configuration
Important: The model field requires the fully qualified class name (e.g., \App\Models\Equipment::class or 'App\\Models\\Equipment').
3. Create Models - Tags Generated Automatically!
That's it! Tags are now automatically generated for all Equipment models. 🎉
Testing with Tinker
You can quickly test the package using Laravel Tinker. Here's a complete walkthrough:
Step 1: Start Tinker
Step 2: Create Tag Configuration
Expected Output:
Step 3: Create Equipment and See Tags Auto-Generate
Step 4: Verify Tags in Database
Step 5: Test Tag Search
Step 6: Test Eager Loading
Step 7: Test Tag Deletion
Quick Verification Script
Copy and paste this into Tinker for a complete test:
Features
✨ Core Features
| Feature | Description |
|---|---|
| Automatic Generation | Tags generated on model creation |
| Multiple Formats | Sequential, Random, Branch-based |
| Polymorphic | Tag any Eloquent model |
| Barcode Support | CODE_128, QR, EAN, UPC, and more |
| Print Labels | Print-ready barcode labels |
| Events System | 4 events for extensibility |
| Bulk Operations | Efficient batch processing |
| RESTful API | Complete API endpoints |
| Caching | Performance optimizations |
| Race Protection | Concurrent tag generation safe |
| Security | Input validation, SQL injection prevention |
| Exceptions | Specific exception classes |
| N+1 Prevention | Query optimization |
| Comprehensive Tests | Unit and feature tests included |
🔢 Tag Generation Formats
Sequential Tags
Perfect for inventory systems requiring ordered numbering:
Random Tags
Great for high-concurrency systems:
Branch-Based Tags
Ideal for multi-location tracking:
📊 Barcode Generation
Generate barcodes in multiple formats for physical tagging:
Via API:
Supported Formats: CODE_128, CODE_39, EAN_13, UPC, QR_CODE, and more
🔔 Events & Webhooks
Hook into tag lifecycle for custom logic:
🔄 Bulk Operations
Efficient batch processing for large datasets:
Bulk Regenerate:
Bulk Delete:
Features:
- Database transactions for consistency
- Individual error handling
- Detailed success/failure reporting
- Automatic logging
📱 RESTful API
Complete API for frontend/mobile apps:
Tag Configurations:
GET /api/tag-configs- List configurationsPOST /api/tag-configs- Create configurationPUT /api/tag-configs/{id}- Update configurationDELETE /api/tag-configs/{id}- Delete configuration
Tags:
GET /api/tags- List all tagsGET /api/tags/{id}- Get specific tagGET /api/tags/{id}/barcode- Generate barcodePOST /api/tags/batch-barcodes- Batch barcodesGET /api/tags/print/labels- Print labels
Meta Endpoints:
GET /api/tag-configs/meta/number-formats- Available formatsGET /api/tag-configs/meta/available-models- Taggable modelsGET /api/tags/meta/barcode-types- Barcode types
Full OpenAPI 3.0 specification available in docs/openapi.yaml
Configuration
The package is highly configurable. Publish the config file:
Key Configuration Options
Environment Variables
Usage
Basic Usage
Accessing Tags
Manual Tag Management
Querying by Tags
Advanced Features
Custom Print Labels
Customize what appears on printed labels:
Label output:
Exception Handling
Custom Tag Generation Logic
Override generation methods in your model:
API Integration
JavaScript/TypeScript Example
Vue.js Example
Performance
Avoiding N+1 Queries
Always use eager loading when loading multiple models with tags:
The package logs N+1 warnings in debug mode.
Caching
Tag configurations are automatically cached:
Cache is automatically invalidated on config updates.
Race Condition Protection
Sequential tag generation uses pessimistic locking:
Performance Targets
- Tag generation: < 100ms (99th percentile)
- API responses: < 200ms (95th percentile)
- Supports 100+ concurrent tag generations
- Handles 1M+ tags per model type
Database Indexes
Automatically created for optimal performance:
- Composite index on
(taggable_type, taggable_id) - Unique constraint on
(taggable_type, taggable_id) - Index on
valuecolumn
Security
Built-in Security Features
✅ Input Validation - Length limits, character whitelisting ✅ SQL Injection Prevention - Parameterized queries, escaped wildcards ✅ XSS Prevention - Output escaping in barcode generation ✅ Error Handling - Secure error messages in production ✅ Rate Limiting - Configurable via middleware ✅ CSRF Protection - Laravel default protection
Security Best Practices
Full security policy available in SECURITY.md
Testing
The package includes a comprehensive test suite:
Test Coverage
- ✅ Tag generation (all formats)
- ✅ Race condition handling
- ✅ Caching behavior
- ✅ API endpoints
- ✅ Barcode generation
- ✅ Bulk operations
- ✅ Event dispatching
- ✅ Exception handling
- ✅ N+1 query prevention
Target: 80%+ code coverage
Documentation
Available Documentation
- README.md - This file (main documentation)
- CHANGELOG.md - Version history and upgrade guides
- CONTRIBUTING.md - Contribution guidelines
- SECURITY.md - Security policy and best practices
- CODE_OF_CONDUCT.md - Community standards
- docs/openapi.yaml - OpenAPI 3.0 specification
Quick Links
- 📖 Installation Guide
- 🚀 Quick Start
- 🔧 Configuration
- 💻 Usage Examples
- 🎯 API Reference
- 🐛 Report Issues
Interactive API Documentation
View interactive API docs with Swagger:
Access at http://localhost:8080
Troubleshooting
Tags Not Generated Automatically
If tags are not being generated when you create models, check the following:
1. Model Uses the Trait
2. TagConfig Uses Full Namespace
❌ Wrong:
✅ Correct:
3. Migrations Are Run
Make sure you've published and run all migrations:
This will create 3 migration files:
create_tags_table.phpcreate_tag_configs_table.phpadd_improvements_to_tagging_tables.php
4. TagConfig Exists
Verify your tag configuration exists:
5. Check Logs
Enable debug mode and check logs for errors:
Tag generation errors are logged to storage/logs/laravel.log.
Common Issues
Issue: "No configuration found for model"
Solution: Create a TagConfig with the correct full namespace:
Issue: "Duplicate tag errors"
Solution: The improvements migration adds unique constraints. If you have existing duplicate tags:
Issue: "Tags are sequential but starting from wrong number"
Solution: Reset the counter in tag_configs:
Issue: "N+1 query warnings in logs"
Solution: Use eager loading:
Debug Mode
Enable verbose logging to troubleshoot issues:
Then check storage/logs/laravel.log for detailed error messages.
Changelog
All notable changes are documented in CHANGELOG.md.
Latest Version
Version 1.1.0 - Current Development
Added:
- Events system (TagCreated, TagUpdated, TagDeleted, TagGenerationFailed)
- Bulk operations (regenerate, delete)
- Custom exception classes
- Caching system for TagConfig lookups
- Race condition protection with pessimistic locking
- Comprehensive test suite
- OpenAPI 3.0 specification
Fixed:
- Race conditions in sequential tag generation
- N+1 query problems
- Missing database constraints
- SQL injection vulnerabilities in search
See CHANGELOG.md for complete history
Contributing
We welcome contributions! Please see CONTRIBUTING.md for details.
Quick Contribution Guide
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests (
composer test) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
Code of Conduct
This project adheres to the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code.
Credits
Author
- Masum Nishat - GitHub
Dependencies
- picqer/php-barcode-generator - Barcode generation
- Laravel Framework - The framework we build upon
Contributors
Thank you to all contributors who have helped make this package better!
License
This package is open-sourced software licensed under the MIT License.
Support
- 🐛 Bug Reports: GitHub Issues
- 💬 Questions: GitHub Discussions
- 📧 Security Issues: See SECURITY.md
Made with ❤️ for the Laravel community
If this package helped you, please consider giving it a ⭐ on GitHub!
All versions of laravel-tagging with dependencies
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/http Version ^10.0|^11.0|^12.0
illuminate/routing Version ^10.0|^11.0|^12.0
picqer/php-barcode-generator Version ^3.0