{"_id":"570dfa69196c4d1900ccd557","project":"563b65bd9e3f2225009fd2bc","__v":5,"user":"570df764b22f0129008dfc23","category":{"_id":"563b6b25e951f60d000b4513","version":"563b65bd9e3f2225009fd2bf","__v":6,"pages":["563c21fd19ae7b0d0050d45b","563c220c7539dd0d00dbee87","563c2218ac77910d00279fe7","563c2233d8f2d20d00448b4f","563c2376913e650d00b65dbd","563c907319ae7b0d0050d528"],"project":"563b65bd9e3f2225009fd2bc","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-11-05T14:43:49.565Z","from_sync":false,"order":1,"slug":"the-basics","title":"The Basics"},"parentDoc":null,"version":{"_id":"563b65bd9e3f2225009fd2bf","project":"563b65bd9e3f2225009fd2bc","__v":4,"createdAt":"2015-11-05T14:20:45.639Z","releaseDate":"2015-11-05T14:20:45.639Z","categories":["563b65be9e3f2225009fd2c0","563b6b25e951f60d000b4513","563c239e260dde0d00c5e890","563c2440260dde0d00c5e891"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"4.0.0","version":"4.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-04-13T07:51:05.791Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"[Hashids](http://hashids.org) is a small open-source library that generates short, unique, non-sequential ids from numbers.\n\n## Configuration\n\nLitepie Hashids requires connection configuration. You can edit the configuration file on `config/hashids.php`\n\n\n## Usage\n\n#### Litepie\\Support\\Facades\\Hashids\n\nThis facade will dynamically pass static method calls to the `hashids` object in the ioc container .\n\n### Examples\nHere you can see an example of just how simple this package is to use. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// You can alias this in config/app.php.\\nuse Litepie\\\\Support\\\\Facades\\\\Hashids;\\n\\nHashids::encode(4815162342);\\n// We're done here - how easy was that, it just works!\\n\\nHashids::decode('doyouthinkthatsairyourebreathingnow');\\n// This example is simple and there are far more methods available.\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Helpers\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\n\\nhashids_encode(4815162342);\\n// We're done here - how easy was that, it just works!\\n\\nhashids_decode('doyouthinkthatsairyourebreathingnow');\\n// This example is simple and there are far more methods available.\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Traits\"\n}\n[/block]\nYou can use hashids traits to decode id (primary key) of the model.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\nuse Litepie\\\\Database\\\\Model;\\n\\nuse Litepie\\\\Hashids\\\\Traits\\\\Hashids;\\n\\nclass MyModel extends Model\\n{\\n    use Hashids;\\n\\n    ......\\n}\\n\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nThis trait overrides two model methods.\n```\n$model->getRouteKey()\n$model->findorFail($hashed_id)\n```","excerpt":"Laravel 5 wrapper for the [Hashids](http://hashids.org)","slug":"hashids","type":"basic","title":"Hashids"}

Hashids

Laravel 5 wrapper for the [Hashids](http://hashids.org)

[Hashids](http://hashids.org) is a small open-source library that generates short, unique, non-sequential ids from numbers. ## Configuration Litepie Hashids requires connection configuration. You can edit the configuration file on `config/hashids.php` ## Usage #### Litepie\Support\Facades\Hashids This facade will dynamically pass static method calls to the `hashids` object in the ioc container . ### Examples Here you can see an example of just how simple this package is to use. [block:code] { "codes": [ { "code": "// You can alias this in config/app.php.\nuse Litepie\\Support\\Facades\\Hashids;\n\nHashids::encode(4815162342);\n// We're done here - how easy was that, it just works!\n\nHashids::decode('doyouthinkthatsairyourebreathingnow');\n// This example is simple and there are far more methods available.", "language": "php" } ] } [/block] [block:api-header] { "type": "basic", "title": "Helpers" } [/block] [block:code] { "codes": [ { "code": "\n\nhashids_encode(4815162342);\n// We're done here - how easy was that, it just works!\n\nhashids_decode('doyouthinkthatsairyourebreathingnow');\n// This example is simple and there are far more methods available.", "language": "php" } ] } [/block] [block:api-header] { "type": "basic", "title": "Traits" } [/block] You can use hashids traits to decode id (primary key) of the model. [block:code] { "codes": [ { "code": "<?php\n\nuse Litepie\\Database\\Model;\n\nuse Litepie\\Hashids\\Traits\\Hashids;\n\nclass MyModel extends Model\n{\n use Hashids;\n\n ......\n}\n", "language": "text" } ] } [/block] This trait overrides two model methods. ``` $model->getRouteKey() $model->findorFail($hashed_id) ```