{"id":20588459,"url":"https://github.com/znck/plug","last_synced_at":"2025-04-14T21:53:25.299Z","repository":{"id":57091632,"uuid":"50701599","full_name":"znck/plug","owner":"znck","description":"A collection of pluggable traits for Eloquent (Laravel) models","archived":false,"fork":false,"pushed_at":"2016-09-27T15:03:06.000Z","size":137,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T21:53:17.062Z","etag":null,"topics":["database","eloquent","laravel","plug"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/znck.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-30T00:57:19.000Z","updated_at":"2021-10-08T23:25:51.000Z","dependencies_parsed_at":"2022-08-22T20:40:51.921Z","dependency_job_id":null,"html_url":"https://github.com/znck/plug","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/znck%2Fplug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/znck%2Fplug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/znck%2Fplug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/znck%2Fplug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/znck","download_url":"https://codeload.github.com/znck/plug/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248968754,"owners_count":21191158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","eloquent","laravel","plug"],"created_at":"2024-11-16T07:24:44.671Z","updated_at":"2025-04-14T21:53:25.276Z","avatar_url":"https://github.com/znck.png","language":"PHP","readme":"Plug\n====\nA collection of pluggable [Eloquent](https://laravel.com/docs/master/eloquent) traits to enhance your Models.\n\n![Plug](cover.png)\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://styleci.io/repos/50701599\"\u003e\n    \u003cimg src=\"https://styleci.io/repos/50701599/shield\" alt=\"StyleCI Status\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://circleci.com/gh/znck/plug\"\u003e\n    \u003cimg src=\"https://circleci.com/gh/znck/plug.svg?style=svg\" alt=\"Build Status\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://coveralls.io/github/znck/plug?branch=master\"\u003e\n    \u003cimg src=\"https://coveralls.io/repos/github/znck/plug/badge.svg?branch=master\u0026style=flat-square\" alt=\"Coverage Status\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"LICENSE\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\" alt=\"Software License\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://packagist.org/packages/znck/plug\"\u003e\n    \u003cimg src=\"https://img.shields.io/packagist/v/znck/plug.svg?style=flat-square\" alt=\"Packagist\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/znck/plug/releases\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/release/znck/plug.svg?style=flat-square\" alt=\"Latest Version\" /\u003e\n  \u003c/a\u003e\n\n  \u003ca href=\"https://github.com/znck/plug/issues\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/issues/znck/plug.svg?style=flat-square\" alt=\"Issues\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## Installation\n\nEither [PHP](https://php.net) 7.0+ is required.\n\nTo get the latest version of Plug, simply require the project using [Composer](https://getcomposer.org):\n\n```bash\n$ composer require znck/plug\n```\n\nInstead, you may of course manually update your require block and run `composer update` if you so choose:\n\n```json\n{\n    \"require\": {\n        \"znck/plug\": \"^0.1\"\n    }\n}\n```\n\nOnce Plug is installed, you can use the plug[gable] traits.\n\n## Usage\nAll features of Plug are provided as traits, so you can directly put them in you model class. Traits would automatically boot. No configuration is required.  \n```php\n\u003c?php namespace App;\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Znck\\Plug\\Eloquent\\Traits\\BelongsToThrough;\n\nclass User extends Model {\n  use BelongsToThrough;\n}\n```\n\nBest practice is to create an abstract model class and use required plugs(traits).  \n```php\n\u003c?php namespace App;\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Znck\\Plug\\Eloquent\\Traits\\BelongsToThrough;\nuse Znck\\Plug\\Eloquent\\Traits\\FixBelongsTo;\nuse Znck\\Plug\\Eloquent\\Traits\\FixMorphTo;\nuse Znck\\Plug\\Eloquent\\Traits\\UuidKey;\nuse Znck\\Plug\\Eloquent\\Traits\\FixForeignKey;\nuse Znck\\Plug\\Eloquent\\Traits\\SelfDecorating;\nuse Znck\\Plug\\Eloquent\\Traits\\SelfValidating;\n\nabstract class UUIDBaseModel extends Model\n{\n    use FixBelongsTo, FixMorphTo, BelongsToThrough, UuidKey, SelfValidating, SelfDecorating, FixForeignKey;\n\n    public $incrementing = true; // Explained below.\n}\n\n```\n\n## Traits\n\n1. **BelongsToThrough**  \nInverse of HasManyThrough relation is missing from Eloquent. This plug (trait) provides `belongsToThrough` relationship. Under the hood, it uses `BelongsToThrough` from [znck/belongs-to-through] package.\n\n1. **FixBelongsTo**  \nTo maintain expected behavior of `belongsTo` relation, Eloquent has introduced a bug.\nIf model has non-incrementing primary key (ex: UUID) and `belongsTo` relation value is null, then if it is eager loaded, it would die due to SQL error. [Issue 12051](https://github.com/laravel/framework/issues/12051)\n\n1. **FixForeignKey**  \nEloquent has misleading behavior when guessing foreign key field name. It takes lowercase singular name of model class and appends `_id` to it, which is very counter-intuitive. Expected behavior is that it should guess foreign key field name from table name. [Issue 10724](https://github.com/laravel/framework/issues/10724)\n\n1. **FixMorphTo**  \nRelation class `MorphTo` inherits `BelongsTo`, so it is prone to same bug.\n\n1. ~~**SelfDecorating**~~ @deprecated   \nIt keeps database entries clean. For example: values in `name` column should start with uppercase letter.\n\n1. ~~**SelfValidating**~~ @deprecated in favour of [znck/repository](https://github.com/znck/repository)   \nIt validates attributes before saving or updating, hence only valid data goes in database.\n\n1. **UuidKey**  \nIt allows to usage of non-incrementing UUID primary keys.\n  ```php\n  class User extends Model {\n    use UuidKey;\n    // Make sure to set $incrementing to false.\n    public $incrementing = false;\n  }\n  ```\n\n## Change log\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Testing\n\n``` bash\n$ composer test\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.\n\n## Security\n\nIf you discover any security related issues, please email :author_email instead of using the issue tracker.\n\n## Credits\n\n- [Rahul Kadyan][link-author]\n- [All Contributors][link-contributors]\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n\n[link-author]: https://github.com/znck\n[link-contributors]: ../../contributors\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fznck%2Fplug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fznck%2Fplug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fznck%2Fplug/lists"}