{"id":29817112,"url":"https://github.com/cybercog/laravel-optimus","last_synced_at":"2025-07-28T20:12:16.706Z","repository":{"id":15283231,"uuid":"77817858","full_name":"cybercog/laravel-optimus","owner":"cybercog","description":"Transform your internal id's to obfuscated integers based on Knuth's integer hash. Laravel wrapper for the Optimus Library by Jens Segers with multiple connections support.","archived":false,"fork":false,"pushed_at":"2025-03-25T12:21:10.000Z","size":107,"stargazers_count":188,"open_issues_count":7,"forks_count":14,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-02T05:19:15.049Z","etag":null,"topics":["cog","cybercog","decrypt","encrypt","hashids","id","laravel","obfuscate","optimus","package","php","public-id"],"latest_commit_sha":null,"homepage":"https://komarev.com/sources/laravel-optimus","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/cybercog.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2017-01-02T07:31:18.000Z","updated_at":"2025-06-06T08:41:58.000Z","dependencies_parsed_at":"2024-03-09T15:28:37.801Z","dependency_job_id":"3294ea34-91fc-425d-9901-bdb45261373d","html_url":"https://github.com/cybercog/laravel-optimus","commit_stats":{"total_commits":62,"total_committers":9,"mean_commits":6.888888888888889,"dds":0.5483870967741935,"last_synced_commit":"b92c3f2c57c70d52ee8b76c76be8921a0d180a2e"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/cybercog/laravel-optimus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cybercog%2Flaravel-optimus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cybercog%2Flaravel-optimus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cybercog%2Flaravel-optimus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cybercog%2Flaravel-optimus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cybercog","download_url":"https://codeload.github.com/cybercog/laravel-optimus/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cybercog%2Flaravel-optimus/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267578003,"owners_count":24110351,"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","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cog","cybercog","decrypt","encrypt","hashids","id","laravel","obfuscate","optimus","package","php","public-id"],"created_at":"2025-07-28T20:12:16.000Z","updated_at":"2025-07-28T20:12:16.678Z","avatar_url":"https://github.com/cybercog.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Optimus\n\n![cog-laravel-optimus](https://user-images.githubusercontent.com/1849174/28744713-5b28fffa-746f-11e7-8ca2-0e2a612bc19c.png)\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://discord.gg/R2sbjAt\"\u003e\u003cimg src=\"https://img.shields.io/static/v1?logo=discord\u0026label=\u0026message=Discord\u0026color=36393f\u0026style=flat-square\" alt=\"Discord\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/cybercog/laravel-optimus/releases\"\u003e\u003cimg src=\"https://img.shields.io/github/release/cybercog/laravel-optimus.svg?style=flat-square\" alt=\"Releases\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/cybercog/laravel-optimus/actions/workflows/tests.yml\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/cybercog/laravel-optimus/tests.yml?style=flat-square\" alt=\"Build\"\u003e\u003c/a\u003e\n\u003ca href=\"https://styleci.io/repos/77817858\"\u003e\u003cimg src=\"https://styleci.io/repos/77817858/shield\" alt=\"StyleCI\"\u003e\u003c/a\u003e\n\u003ca href=\"https://scrutinizer-ci.com/g/cybercog/laravel-optimus/?branch=master\"\u003e\u003cimg src=\"https://img.shields.io/scrutinizer/g/cybercog/laravel-optimus.svg?style=flat-square\" alt=\"Code Quality\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/cybercog/laravel-optimus/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/cybercog/laravel-optimus.svg?style=flat-square\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Introduction\n\nLaravel wrapper for the [Optimus Library](https://github.com/jenssegers/optimus) by [Jens Segers](https://github.com/jenssegers) with multiple connections support. Optimus is a small open-source library that generates short, unique, non-sequential ids from numbers. With this library, you can transform your internal id's to obfuscated integers based on Knuth's integer hash. It is similar to Hashids, but will generate integers instead of random strings. It is also super fast.\n\n## Contents\n \n- [Features](#features)\n- [Installation](#installation)\n- [Configuration](#configuration)\n- [Usage](#usage)\n  - [Examples](#examples)\n- [Changelog](#changelog)\n- [Contributing](#contributing)\n- [Testing](#testing)\n- [Security](#security)\n- [Contributors](#contributors)\n- [Alternatives](#alternatives)\n- [License](#license)\n- [About CyberCog](#about-cybercog)\n\n## Features\n\n- Configurable multiple Optimus connections support.\n- Implicit route model binding.\n- Designed to work with Laravel Eloquent models.\n- Dependency Injection ready.\n- Includes Facade.\n- Following PHP Standard Recommendations:\n  - [PSR-1 (Basic Coding Standard)](http://www.php-fig.org/psr/psr-1/).\n  - [PSR-2 (Coding Style Guide)](http://www.php-fig.org/psr/psr-2/).\n  - [PSR-4 (Autoloading Standard)](http://www.php-fig.org/psr/psr-4/).\n- Covered with unit tests.\n\n## Installation\n\nFirst, pull in the package through Composer.\n\n```shell\ncomposer require cybercog/laravel-optimus\n```\n\n#### Register Package Manually (optional)\n\nIf you disabled package auto-discovery you can register it manually.\n\nInclude the service provider within `app/config/app.php`.\n\n```php\n'providers' =\u003e [\n    Cog\\Laravel\\Optimus\\Providers\\OptimusServiceProvider::class,\n],\n```\n\nIf you want you can use the [facade](http://laravel.com/docs/facades). Add the reference in `config/app.php` to your aliases array.\n\n```php\n'aliases' =\u003e [\n    'Optimus' =\u003e Cog\\Laravel\\Optimus\\Facades\\Optimus::class,\n],\n```\n\n## Configuration\n\nLaravel Optimus requires connection configuration. To get started, you'll need to publish config file:\n\n```shell\nphp artisan vendor:publish --provider=\"Cog\\Laravel\\Optimus\\Providers\\OptimusServiceProvider\" --tag=\"config\"\n```\n\nThis will create a `config/optimus.php` file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.\n\n#### Default Connection Name\n\nThis option `default` is where you may specify which of the connections below you wish to use as your default connection for all work. Of course, you may use many connections at once using the manager class. The default value for this setting is `main`.\n\n#### Optimus Connections\n\nThis option `connections` is where each of the connections are setup for your application. Example configuration has been included, but you may add as many connections as you would like.\n\n#### Optimus numbers generation\n\nTo get started you will need 3 keys in main connection;\n\n- `prime`: Large prime number lower than `2147483647`\n- `inverse`: The inverse prime so that `(PRIME * INVERSE) \u0026 MAXID == 1`\n- `random`: A large random integer lower than `2147483647`\n\nLuckily for you, there is console command that can do all of this for you, just run the following command:\n\n```shell\nphp vendor/bin/optimus spark\n```\n\nCopy-paste generated integers to your connection config.\n\n## Usage\n\n#### OptimusManager\n\nThis is the class of most interest. It is bound to the ioc container as `optimus` and can be accessed using the `Facades\\Optimus` facade. This class implements the ManagerInterface by extending AbstractManager. The interface and abstract class are both part of [Graham Campbell's](https://github.com/GrahamCampbell) [Laravel Manager](https://github.com/GrahamCampbell/Laravel-Manager) package, so you may want to go and checkout the docs for how to use the manager class over at that repository. Note that the connection class returned will always be an instance of `Jenssegers\\Optimus\\Optimus`.\n\n#### Facades\\Optimus\n\nThis facade will dynamically pass static method calls to the `optimus` object in the ioc container which by default is the `OptimusManager` class.\n\n#### Providers\\OptimusServiceProvider\n\nThis class contains no public methods of interest. This class should be added to the providers array in `config/app.php`. This class will setup ioc bindings.\n\n#### Traits\\OptimusEncodedRouteKey\n\nThis trait can be used in an Eloquent model to enable automatic route model binding. You can then type hint a model in a route closure or a controller and Laravel will try to find it based on the encoded ID. \n\n### Examples\n\nHere you can see an example of just how simple this package is to use. Out of the box, the default adapter is `main`. After you enter your authentication details in the config file, it will just work:\n\n#### Encode ID\n\n```php \nCog\\Laravel\\Optimus\\Facades\\Optimus::encode(20); // 1535832388\n```\n\n#### Decode ID\n\n```php\nCog\\Laravel\\Optimus\\Facades\\Optimus::decode(1535832388); // 20\n```\n\n#### Alter Optimus connection\n\nThe Optimus manager will behave like it is a `Jenssegers\\Optimus\\Optimus`. If you want to call specific connections, you can do that with the connection method:\n\n```php\nuse Cog\\Laravel\\Optimus\\Facades\\Optimus;\n\n// Writing this…\nOptimus::connection('main')-\u003eencode($id);\n\n// …is identical to writing this\nOptimus::encode($id);\n\n// and is also identical to writing this.\nOptimus::connection()-\u003eencode($id);\n\n// This is because the main connection is configured to be the default.\nOptimus::getDefaultConnection(); // This will return main.\n\n// We can change the default connection.\nOptimus::setDefaultConnection('alternative'); // The default is now alternative.\n```\n\n#### Dependency Injection\n\nIf you prefer to use dependency injection over facades like me, then you can inject the manager:\n\n```php\nuse Cog\\Laravel\\Optimus\\OptimusManager;\n\nclass Foo\n{\n    protected $optimus;\n\n    public function __construct(OptimusManager $optimus)\n    {\n        $this-\u003eoptimus = $optimus;\n    }\n    \n    public function bar($id)\n    {\n        return $this-\u003eoptimus-\u003eencode($id)\n    }\n}\n\napp()-\u003emake('Foo')-\u003ebar(20);\n```\n\n#### Implicit route model binding\n\nTo enable [implicit route model binding](https://laravel.com/docs/5.5/routing#implicit-binding) based on the encoded ID, all you need to do is [configure the prime numbers](#optimus-numbers-generation) and use the `Cog\\Laravel\\Optimus\\Traits\\OptimusEncodedRouteKey` trait in your model.\n\nIf you don't want to use the default Optimus connection, you can specify a custom connection by adding an `$optimusConnection` property to you model.\n\n```php\nuse Cog\\Laravel\\Optimus\\Traits\\OptimusEncodedRouteKey;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass YourModel extends Model\n{\n    use OptimusEncodedRouteKey;\n    \n    protected $optimusConnection = 'custom'; // optional\n}\n```\n\nNow you can type hint your model in a route closure or controller and Laravel will use the encoded ID to query the database.\n\n*Note: Implicit route model binding requires Laravel's `Illuminate\\Routing\\Middleware\\SubstituteBindings` middleware, which is part of the `web` middleware group.*\n\n```php\nRoute::get('url/to/{model}', function (YourModel $model) {\n    // ...\n})-\u003emiddleware('web');\n```\n\nTo generate URL's to these routes you can either get the encoded route key:\n\n```php\n$encodedId = $model-\u003egetRouteKey();\n$url = url(\"url/to/{$encodedId}\");\n```\n\nOr you can use named routes and pass it the model. Laravel will do the rest.\n\n```php\n$url = route('my.named.route', $model);\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Testing\n\nRun the tests with:\n\n```shell\nvendor/bin/phpunit\n```\n\n## Security\n\nIf you discover any security related issues, please email anton@komarev.com instead of using the issue tracker.\n\n## Contributors\n\n| \u003ca href=\"https://github.com/antonkomarev\"\u003e![@antonkomarev](https://avatars.githubusercontent.com/u/1849174?s=110)\u003cbr /\u003eAnton Komarev\u003c/a\u003e | \u003ca href=\"https://github.com/ivanvermeyen\"\u003e![@ivanvermeyen](https://avatars.githubusercontent.com/u/3598622?s=110)\u003cbr /\u003eIvan Vermeyen\u003c/a\u003e | \u003ca href=\"https://github.com/tur-nr\"\u003e![@tur-nr](https://avatars.githubusercontent.com/u/817134?s=110)\u003cbr /\u003eChristopher Turner\u003c/a\u003e | \u003ca href=\"https://github.com/ahmedbally\"\u003e@ahmedbally\u003cbr /\u003eAhmed Bally\u003c/a\u003e |  \n| :---: | :---: | :---: | :---: |\n\n[Laravel Optimus contributors list](../../contributors)\n\nPackage was inspired by [Laravel Hashids](https://github.com/vinkla/laravel-hashids) package.\n\nThis package is a wrapper for [Optimus Library](https://github.com/jenssegers/optimus).\n\n## Alternatives\n\n- [vinkla/laravel-hashids](https://github.com/vinkla/laravel-hashids)\n- [propaganistas/laravel-fakeid](https://github.com/Propaganistas/Laravel-FakeId)\n\n*Feel free to add more alternatives as Pull Request.*\n\n## License\n\n- `Laravel Optimus` package is open-sourced software licensed under the [MIT license](LICENSE) by [Anton Komarev].\n\n## 🌟 Stargazers over time\n\n[![Stargazers over time](https://chart.yhype.me/github/repository-star/v1/77817858.svg)](https://yhype.me?utm_source=github\u0026utm_medium=cybercog-laravel-optimus\u0026utm_content=chart-repository-star-cumulative)\n## About CyberCog\n\n[CyberCog](https://cybercog.su) is a Social Unity of enthusiasts. Research the best solutions in product \u0026 software development is our passion.\n\n- [Follow us on Twitter](https://twitter.com/cybercog)\n- [Read our articles on Medium](https://medium.com/cybercog)\n\n\u003ca href=\"https://cybercog.su\"\u003e\u003cimg src=\"https://cloud.githubusercontent.com/assets/1849174/18418932/e9edb390-7860-11e6-8a43-aa3fad524664.png\" alt=\"CyberCog\"\u003e\u003c/a\u003e\n\n[Anton Komarev]: https://komarev.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcybercog%2Flaravel-optimus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcybercog%2Flaravel-optimus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcybercog%2Flaravel-optimus/lists"}