{"id":20128946,"url":"https://github.com/intervention/eloquent-hashid","last_synced_at":"2025-04-09T15:51:21.852Z","repository":{"id":56992741,"uuid":"338608187","full_name":"Intervention/eloquent-hashid","owner":"Intervention","description":"Configurable HashId Trait for Laravel Eloquent models","archived":false,"fork":false,"pushed_at":"2024-11-27T16:27:52.000Z","size":17,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-23T18:06:08.300Z","etag":null,"topics":[],"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/Intervention.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":"2021-02-13T15:45:34.000Z","updated_at":"2024-12-06T12:04:40.000Z","dependencies_parsed_at":"2024-03-13T17:46:41.056Z","dependency_job_id":"8004e8a3-5ba7-40c3-a91a-405c07133832","html_url":"https://github.com/Intervention/eloquent-hashid","commit_stats":{"total_commits":14,"total_committers":1,"mean_commits":14.0,"dds":0.0,"last_synced_commit":"8dfcd4da020e19675c03ded44912724f9fa61bec"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Intervention%2Feloquent-hashid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Intervention%2Feloquent-hashid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Intervention%2Feloquent-hashid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Intervention%2Feloquent-hashid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Intervention","download_url":"https://codeload.github.com/Intervention/eloquent-hashid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248063954,"owners_count":21041854,"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":[],"created_at":"2024-11-13T20:30:44.567Z","updated_at":"2025-04-09T15:51:21.816Z","avatar_url":"https://github.com/Intervention.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Intervention Eloquent HashID\n\n[![Latest Version](https://img.shields.io/packagist/v/intervention/eloquent-hashid.svg)](https://packagist.org/packages/intervention/eloquent-hashid)\n\nThis package provides a trait to easily encode and decode [hashids](https://github.com/vinkla/hashids) in your Eloquent models. Every model gets an attribute and a scope for hashid queries.\n\n## Installation\n\nYou can install this package with Composer.\n\nRequire the package via Composer:\n\n    $ composer require intervention/eloquent-hashid\n\nLaravel will automatically discover the packages service provider class.\n\n## Setup\n\nAfter installation you're able to publish the configuration file to your Laravel application with the following command.\n\n    $ php artisan vendor:publish --provider=\"Intervention\\EloquentHashid\\Laravel\\EloquentHashidServiceProvider\"\n\nYou will find a new config file in `config/hashid.php`, which you can customize. **I strongly suggest to change at least the `salt_prefix` option to your own value.**\n\nNow you can include the trait `Intervention\\EloquentHashid\\HasHashid` in your [Eloquent Model](https://laravel.com/docs/eloquent) to add the hashid features.\n\n```php\nuse Intervention\\EloquentHashid\\HasHashid;\n\nclass Item extends Model\n{\n    use HasHashid;\n}\n```\n\n## Usage\n\n### Code Example\n\nEvery Eloquent Model gets a new `hashid` attribute, which is created based on the models classname, the key and the salt prefix. You're also able to query models with the now added `hashid()` scope.\n\n#### Access hashid attribute\n\n```php\n$item = App\\Models\\Item::find(123);\n\n// access hashid attribute\n$hashid = $item-\u003ehashid\n```\n\n#### Query models\n\n```php\n// query model with scope\n$item = App\\Models\\Item::hashid('Ma93ka')-\u003efirstOrFail();\n\n// scope can also select multiple items by array\n$item = App\\Models\\Item::hashid(['Ma93ka', 'Op92ae'])-\u003eget();\n\n// scope query in one call\n$item = App\\Models\\Item::findByHashid('Ma93ka');\n\n// scope query in one call, throw exception if no model was found\n$item = App\\Models\\Item::findByHashidOrFail('Ma93ka');\n```\n\n#### Route Model Binding\n\nEloquent models can be resolved by their hashid in routes by defining a custom key.\n\n```php\nuse App\\Models\\Item;\n\nRoute::get('/items/{item:hashid}', function (Item $item) {\n    return $item;\n});\n```\n\n## Authors\n\nThis library is developed and maintained by [Oliver Vogel](https://intervention.io)\n\n## License\n\nIntervention Eloquent HashID is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintervention%2Feloquent-hashid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fintervention%2Feloquent-hashid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintervention%2Feloquent-hashid/lists"}