- What is znck/plug and what Eloquent traits does it provide?
- znck/plug is a small collection of pluggable traits for Laravel Eloquent models. It includes traits such as BelongsToThrough, UuidKey, FixBelongsTo, FixMorphTo, FixForeignKey, and SelfDecorating. The traits are designed to be added directly to a model and boot automatically, with no service provider or configuration file.
- How do I install znck/plug in a Laravel app?
- Install it with composer require znck/plug, or add znck/plug: ^0.1 to your require block and run composer update. The package declares PHP 7.0+ and Laravel 5.x-era illuminate constraints, so modern Laravel and PHP projects may fail dependency resolution. If that happens, do not force it into production without auditing or vendoring the needed traits.
- Is znck/plug compatible with Laravel 9, 10, 11, or PHP 8?
- The package targets PHP 7.0+ and Laravel 5.x-era illuminate components, and its last release was in 2016. It is not expected to resolve or run cleanly on Laravel 9, 10, 11, or PHP 8.x without a fork or widened constraints. Revalidate any trait against current Eloquent internals before relying on it.
- Do I need to register a service provider or publish config for znck/plug?
- No. znck/plug has no service provider, facade, config file, or migrations; its features are traits that boot automatically when used in a model. You simply add the trait to your model or a shared base model. There is nothing to publish or register.
- How does the BelongsToThrough trait work in znck/plug?
- BelongsToThrough is a trait that adds a belongsToThrough relation helper for traversing intermediate relations, such as Comment to User through Post. You add the trait to the model and call the relation method in the same way you would use other Eloquent relations. Because the package is legacy and unmaintained, test the generated SQL and eager loading behavior against your Laravel version.
- Can znck/plug traits conflict with model events or other traits?
- Yes. Traits are composed at the class level and multiple traits can collide if they hook the same Eloquent lifecycle methods, such as saving, creating, getAttribute, or setAttribute. They can also interact with observers, soft deletes, and event ordering. Test combinations carefully, and remember that insert, upsert, and query-builder writes bypass model events.
- How do I add UUID primary keys to an Eloquent model with znck/plug?
- Use the UuidKey trait on the model and ensure the primary key column is a UUID-compatible type, such as char(36) or an appropriate uuid column. The trait handles key generation at the model layer; schema changes and backfills are still your responsibility. For new projects, consider Laravel's built-in UUID and ULID support instead.
- Is znck/plug maintained and safe for production use?
- No, it should not be treated as a safe runtime dependency without mitigation. The last release was 2016-09-27, it has a single maintainer, very low adoption, and old CircleCI badges that are not a live build signal. The MIT license and lack of network surface keep security exposure low, but unpatched dependencies and no CVE process are audit concerns.
- What are alternatives to znck/plug if it is abandoned or incompatible?
- For UUID keys, use Laravel's built-in HasUuids or HasUlids traits. For nested relations, use native relationship queries or a maintained package that supports your current Laravel version. For small model behaviors such as slugs or sortable columns, implement them in your own base model or shared concern.
- Should I vendor or reimplement znck/plug traits instead of requiring the package?
- The recommended path is to cherry-pick only the traits you need into your own namespace, keep the MIT header, and add unit and integration tests. A full fork is only justified if you need a large subset and expect upstream movement, which has not happened in years. Many single-purpose traits, such as UUID keys or slug generation, are small enough to reimplement outright.