- How do I use this package in Laravel to replace JSON API responses with CBOR?
- Install via Composer, then use middleware to negotiate CBOR responses. For example, create a middleware that checks the `Accept` header for `application/cbor` and returns CBOR-encoded data using the `Encoder` class. Laravel’s response system can be extended to support CBOR via a custom response factory.
- Does this package support Laravel Eloquent for storing CBOR-encoded data in MySQL/PostgreSQL?
- Yes, you can store CBOR data in a BLOB or JSONB column and decode it on retrieval using Eloquent accessors. The package provides a type-safe API, so you can normalize CBOR to PHP arrays or objects before processing in Laravel models.
- What Laravel versions and PHP requirements does spomky-labs/cbor-php support?
- The package requires PHP 8.0+ and is tested with Laravel 9+ (PHP 8.0+) and 10+ (PHP 8.1+). It has no Laravel-specific dependencies, making it framework-agnostic but fully compatible with modern Laravel applications.
- How does the streaming decoder help with large datasets in Laravel?
- The streaming decoder processes CBOR data incrementally, reducing memory usage for large payloads like logs or IoT telemetry. In Laravel, this is useful for queue workers or background jobs handling big files without memory overload.
- Can I use custom tags for domain-specific validation in Laravel FormRequests?
- Yes, the package supports extensible tags. You can define custom tags for validation rules in Laravel FormRequests by implementing the `TagInterface` and registering them with the decoder. This is useful for enforcing schema constraints on CBOR payloads.
- What’s the performance difference between this CBOR library and JSON/XML in Laravel?
- CBOR reduces payload size by 50-80% compared to JSON, improving API response times and database storage efficiency. Benchmarking shows faster parsing/encoding for complex nested data, especially with optional `ext-gmp` or `ext-bcmath` for large integers.
- How do I debug CBOR payloads in Laravel logs or middleware?
- Use the `Decoder` class to log raw CBOR data as normalized PHP arrays. For middleware, create a helper to convert CBOR to readable JSON for logging: `json_encode($decoder->decode($request->getContent())->normalize())`.
- Are there alternatives to this package for CBOR in PHP/Laravel?
- Other options include `josegonzalez/cbor.php` (older, less maintained) or `rupor-gmbh/cbor` (simpler but lacks streaming/extensible tags). This package stands out for its PHP 8+ type safety, streaming support, and Laravel-friendly features like normalization.
- How do I handle indefinite-length CBOR objects in Laravel for dynamic data?
- The package natively supports indefinite-length items (e.g., arrays/maps). Use `Decoder::create()->decode($stream)` with a `StringStream` for dynamic data. In Laravel, this is useful for processing unbounded logs or sensor streams without memory limits.
- What’s the maintenance status of this package, and how do I stay updated?
- The package follows semantic versioning and is actively maintained by Spomky-Labs. Monitor the [GitHub repo](https://github.com/Spomky-Labs/cbor-php) for updates, or subscribe to Packagist notifications. Breaking changes are rare and documented in release notes.