{"id":16461939,"url":"https://github.com/milwad-dev/laravel-attributes","last_synced_at":"2025-04-08T09:09:09.842Z","repository":{"id":65557031,"uuid":"521337571","full_name":"milwad-dev/laravel-attributes","owner":"milwad-dev","description":"The laravel-attributes package allows Laravel developers to easily add and manage custom attributes on Eloquent models","archived":false,"fork":false,"pushed_at":"2025-03-01T16:06:22.000Z","size":87,"stargazers_count":203,"open_issues_count":0,"forks_count":10,"subscribers_count":3,"default_branch":"1.x","last_synced_at":"2025-04-01T08:39:00.447Z","etag":null,"topics":["attribute","composer","eloquent","larave-attribute","laravel","laravel-attribute-library","laravel-attribute-package","laravel-attribute-polymorphic","laravel-library","laravel-package","laravel-packages","package","php","php-library","polymorphic"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/milwad/laravel-attributes","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/milwad-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-04T16:25:11.000Z","updated_at":"2025-03-23T11:21:39.000Z","dependencies_parsed_at":"2023-01-29T10:15:13.603Z","dependency_job_id":"3ae00db0-12df-4a57-bbbf-a1a38d042c7b","html_url":"https://github.com/milwad-dev/laravel-attributes","commit_stats":{"total_commits":112,"total_committers":6,"mean_commits":"18.666666666666668","dds":0.1428571428571429,"last_synced_commit":"2f5904ba8fdf8dae73df4f968075c2ba267da27d"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milwad-dev%2Flaravel-attributes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milwad-dev%2Flaravel-attributes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milwad-dev%2Flaravel-attributes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milwad-dev%2Flaravel-attributes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/milwad-dev","download_url":"https://codeload.github.com/milwad-dev/laravel-attributes/tar.gz/refs/heads/1.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809964,"owners_count":20999816,"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":["attribute","composer","eloquent","larave-attribute","laravel","laravel-attribute-library","laravel-attribute-package","laravel-attribute-polymorphic","laravel-library","laravel-package","laravel-packages","package","php","php-library","polymorphic"],"created_at":"2024-10-11T11:09:56.128Z","updated_at":"2025-04-08T09:09:09.820Z","avatar_url":"https://github.com/milwad-dev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Attributes\n\n\u003cimg src=\"https://banners.beyondco.de/Laravel%20Attributes.png?theme=dark\u0026packageManager=composer+require\u0026packageName=milwad%2Flaravel-attributes\u0026pattern=boxes\u0026style=style_2\u0026description=Make+attributes+easy+for+Laravel\u0026md=1\u0026showWatermark=1\u0026fontSize=100px\u0026images=https%3A%2F%2Flaravel.com%2Fimg%2Flogomark.min.svg\" alt=\"Laravel-Attributes\"\u003e\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/milwad/laravel-attributes.svg?style=flat-square)](https://packagist.org/packages/milwad/laravel-attributes)\n[![Total Downloads](https://img.shields.io/packagist/dt/milwad/laravel-attributes.svg?style=flat-square)](https://packagist.org/packages/milwad/laravel-attributes)\n[![License](https://img.shields.io/packagist/l/milwad/laravel-attributes)](https://packagist.org/packages/milwad/laravel-attributes)\n[![Passed Tests](https://github.com/milwad-dev/laravel-attributes/actions/workflows/run-tests.yml/badge.svg)](https://github.com/milwad-dev/laravel-attributes/actions/workflows/run-tests.yml)\n[![PHP Version Require](https://img.shields.io/packagist/dependency-v/milwad/laravel-attributes/php)](https://packagist.org/packages/milwad/laravel-attributes)\n***\nThe `laravel-attributes` package is a tool designed to help Laravel developers easily manage and implement custom attributes in their projects. It enables you to define attributes directly on Eloquent models, making it simpler to handle dynamic or calculated properties without directly modifying the database schema. With this package, you can create and configure attribute sets for models, making it easier to organize and extend data handling in Laravel applications. It's especially useful for projects that require customizable and flexible data models. \u003cbr\u003e\nYou don't have any stress for attributes! You can create attributes for any model and display like drink water :)\n\n# Requirements\n***\n\n- `PHP: ^8.0`\n- `Laravel Framework: ^9.0`\n\n| Attributes | L9                 | L10                |\n|------------|--------------------|--------------------|\n| 1.0        | :white_check_mark: | :white_check_mark: |\n| 1.1        | :white_check_mark: | :white_check_mark: |\n\n# Installation\n***\n```\ncomposer require milwad/laravel-attributes\n```\nAfter publish config files.\u003cbr\u003e\n```bash\nphp artisan vendor:publish --provider=\"Milwad\\LaravelAttributes\\LaravelAttributesServiceProvider\"\n```\nAfter publish, you migrate the migration file.\n```\nphp artisan migrate\n```\n\n# Usage\nFirst, you use trait in model.\n```php\n\u003c?php\n\nnamespace App\\Models;\n\nuse Illuminate\\Database\\Eloquent\\Factories\\HasFactory;\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Milwad\\LaravelAttributes\\Traits\\Attributable;\n\nclass Product extends Model\n{\n    use HasFactory, Attributable;\n}\n```\n\nAfter, you have access to `attributes` relation and etc... .\n\n## Save attribute\n\nIf you want to attach attribute to a model, you can use `attachAttribute` method. \u003cbr\u003e\n`attachAttribute` method take a `title` and `value`.\n\n```php\n$product = Product::query()-\u003ecreate([\n    'name' =\u003e 'milwad',\n    'content' =\u003e 'laravel attributes',\n]);\n\n$product-\u003eattachAttribute('age', '17');\n```\n\n## Save attribute multiple\n\nIf you have multiple attributes you can use `attachAttributes` method to save attributes for a model.\n\n```php\n$product = Product::query()-\u003ecreate([\n    'name' =\u003e 'milwad',\n    'content' =\u003e 'text',\n]);\n\n$data = [\n    [\n        'title' =\u003e 'milwad',\n        'value' =\u003e 'developer',\n    ],\n    [\n        'title' =\u003e 'milwad2',\n        'value' =\u003e 'developer2',\n    ],\n    [\n        'title' =\u003e 'milwad3',\n        'value' =\u003e 'developer3',\n    ],\n    [\n        'title' =\u003e 'milwad4',\n        'value' =\u003e 'developer4',\n    ],\n    [\n        'title' =\u003e 'milwad5',\n        'value' =\u003e 'developer5',\n    ],\n    [\n        'title' =\u003e 'milwad6',\n        'value' =\u003e 'developer6',\n    ],\n];\n\n$product-\u003eattachAttributes($data);\n```\n\n## Get attributes with query\n\nIf you want to retrieve attributes from relation you can use `attributes`.\n\n```php\n$product = Product::query()-\u003ewith('attributes')-\u003eget();\n\n$product-\u003eattributes\n```\n\n## Check attribute value is exists\n\nMaybe you want to check one model has an attribute value you can use `hasAttributeValue` method.\n\n```php\nif ($product-\u003ehasAttributeValue('17')) {\n    return 'attribute value';\n}\n\nreturn 'no attribute value';\n```\n\n## Check attribute value is exists\n\nMaybe you want to check one model has an attribute title you can use `hasAttributeTitle` method.\n\n```php\nif ($product-\u003ehasAttributeTitle('milwad')) {\n    return 'attribute title';\n}\n\nreturn 'no attribute title';\n```\n\n## Delete all attributes\n\nIf you want to delete all attributes of one model you can use `deleteAllAttribute` method.\n\n```php\n$product-\u003edeleteAllAttribute();\n```\n\n## Delete special attributes\n\nIf you want to delete specific attribute of a model you can use `deleteAttribute` method.\n\n```php\n$product-\u003edeleteAttribute('title', 'value');\n```\n\n## Delete special attributes by title\n\nIf you want to delete specific attribute by title you can use `deleteAttributeByTitle` method. \u003cbr\u003e\n\u003e Maybe you have two attributes with same title, if you delete with this method, will be deleted two attributes\n\n```php\n$product-\u003edeleteAttributeByTitle('title');\n```\n\n## Delete special attributes by value\n\nIf you want to delete specific attribute by value you can use `deleteAttributeByValue` method. \u003cbr\u003e\n\u003e Maybe you have two attributes with same value, if you delete with this method, will be deleted two attributes\n\n```php\n$product-\u003edeleteAttributeByValue('value');\n```\n\n## Testing\n\nRun the tests with:\n\n``` bash\nvendor/bin/pest\ncomposer test\ncomposer test-coverage\n```\n\n## Customize\n\nIf you want change migration table name or change default model you can use `laravel-attributes` config that exists in `config` folder.\n\n```php\n\u003c?php\n\nreturn [\n    /*\n     * Table config\n     *\n     * Here it's a config of migrations.\n     */\n    'tables' =\u003e [\n        /*\n         * Get table name of migration.\n         */\n        'name' =\u003e 'attributes',\n\n        /*\n         * Use uuid as primary key.\n         */\n        'uuids' =\u003e false, // Also in beta !!!\n    ],\n\n    /*\n     * Model class name for attributes table.\n     */\n    'attributes_model' =\u003e \\Milwad\\LaravelAttributes\\Attribute::class,\n];\n```\n\n# License\n* This package is created and modified by \u003ca href=\"https://github.com/milwad-dev\" target=\"_blank\"\u003eMilwad Khosravi\u003c/a\u003e for Laravel \u003e= 9 and is released under the MIT License.\n\n## Contributing\n\nThis project exists thanks to all the people who\ncontribute. [CONTRIBUTING](https://github.com/milwad-dev/laravel-attributes/graphs/contributors)\n\n\u003ca href=\"https://github.com/milwad-dev/laravel-attributes/graphs/contributors\"\u003e\u003cimg src=\"https://opencollective.com/laravel-attributes/contributors.svg?width=890\u0026button=false\" /\u003e\u003c/a\u003e\n\n## Security\n\nIf you've found a bug regarding security please mail [milwad.dev@gmail.com](mailto:milwad.dev@gmail.com) instead of\nusing the issue tracker.\n\n## Donate\n\nIf this package is helpful for you, you can buy a coffee for me :) ❤️\n\n- Iraninan Gateway: https://daramet.com/milwad_khosravi\n- Paypal Gateway: SOON\n- MetaMask Address: `0xf208a562c5a93DEf8450b656c3dbc1d0a53BDE58`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilwad-dev%2Flaravel-attributes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmilwad-dev%2Flaravel-attributes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilwad-dev%2Flaravel-attributes/lists"}