{"id":22491802,"url":"https://github.com/always-open/sidekick","last_synced_at":"2025-10-28T00:12:26.643Z","repository":{"id":41333724,"uuid":"377797138","full_name":"always-open/sidekick","owner":"always-open","description":null,"archived":false,"fork":false,"pushed_at":"2023-08-15T17:34:28.000Z","size":71,"stargazers_count":1,"open_issues_count":1,"forks_count":2,"subscribers_count":7,"default_branch":"4.x","last_synced_at":"2024-11-22T18:06:22.316Z","etag":null,"topics":["hacktoberfest","helper","laravel"],"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/always-open.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null},"funding":{"github":"always-open"}},"created_at":"2021-06-17T10:50:10.000Z","updated_at":"2022-08-17T00:57:37.000Z","dependencies_parsed_at":"2022-08-26T09:30:17.835Z","dependency_job_id":null,"html_url":"https://github.com/always-open/sidekick","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/always-open%2Fsidekick","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/always-open%2Fsidekick/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/always-open%2Fsidekick/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/always-open%2Fsidekick/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/always-open","download_url":"https://codeload.github.com/always-open/sidekick/tar.gz/refs/heads/4.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228508031,"owners_count":17931263,"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":["hacktoberfest","helper","laravel"],"created_at":"2024-12-06T18:11:15.588Z","updated_at":"2025-10-28T00:12:21.398Z","avatar_url":"https://github.com/always-open.png","language":"PHP","funding_links":["https://github.com/sponsors/always-open"],"categories":[],"sub_categories":[],"readme":"# A collection of helper classes to make fighting the good fight easier\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/always-open/sidekick.svg?style=flat-square)](https://packagist.org/packages/always-open/sidekick)\n[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/always-open/sidekick/run-tests?label=tests)](https://github.com/always-open/sidekick/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/always-open/sidekick/Check%20\u0026%20fix%20styling?label=code%20style)](https://github.com/always-open/sidekick/actions?query=workflow%3A\"Check+%26+fix+styling\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/always-open/sidekick.svg?style=flat-square)](https://packagist.org/packages/always-open/sidekick)\n[![Maintainability](https://api.codeclimate.com/v1/badges/49ee42b487aad513866f/maintainability)](https://codeclimate.com/github/always-open/sidekick/maintainability)\n\nCollection of helper classes to make fighting the good fight even easier.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require always-open/sidekick\n```\n\n## Version Support\n| Sidekick version | PHP Version     |\n|------------------|-----------------|\n| 1.x              | PHP 7.4 and 8.x |\n| 4.x              | PHP 8.x+        |\n\n## Usage\n\n### Helpers\n\n#### String Helper\n```php\n$ids = AlwaysOpen\\Helpers\\Strings::stringIdsToCollection('1,3,45, asdf,66,1,45,3');\nvar_dump($ids);\n```\n#### Routes Helper\nThis helper stops redirect loops where a `url()-\u003eprevious()` might be used but the user could have directly input the \nurl so `previous` and `current` are the same. This helper stops that from happening while allowing you to specify where \nto go if that scenario happens.\n\nIf the user can edit user profiles and reach it from multiple screens the redirect response after saving might look like \nthis:\n```php\nreturn response()-\u003eredirectTo(\n    AlwaysOpen\\Helpers\\Routes::toRouteIfBackIsLoop('user.report')\n);\n```\n\nHere the user will either go to their previous URL or get sent to the user report.\n\n\n### Traits\n\n#### ByName\nAdd the trait to your model:\n```php\n\u003c?php\n\nnamespace App\\Models;\n\nnamespace AlwaysOpen\\Sidekick\\Models\\Traits\\ByName;\n\nclass OrderStage extends Model\n{\n    use ByName;\n    \n    const NEXT_DAY = 'Next Day';\n   ...\n}\n```\nUse the trait to get the model by its name:\n```php\n$overnight = OrderStage::byName('overnight');\n```\n\nWorks nicely when you're doing work with consts:\n```php\n$overnight = OrderStage::byName(OrderStage::NEXT_DAY);\n```\n\n#### CascadeUpdate\nThis trait is good if you need to update a last updated timestamp on related models such as a parent child relationship \nor line items on a document.\n\nIn the example class `Docuemnt` has multiple `LineItem` instances as children.\n\nWithin this exmaple you will need to override the `getRelationshipsToUpdate` method:\n```php\nclass LineItem extends Model\n{\n    use CascadeUpdate;\n\n    public function getRelationshipsToUpdate() : array\n    {\n        return [\n            'Document',\n        ];\n    }\n\n    public function CascadeUpdate() : HasOne\n```\n\nWhen an instance of LineItem is saved the `UPDATED_AT` column on the owner `Document` will be updated as well.\n\n#### Ordered\nThis trait ensures that all instances have a sort column value that is next in line. Future TODO is to make it update \nother instances when one of their sort values is updated to keep all in proper order.\n\n\n## Testing\n\n```bash\ncomposer test\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](.github/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [AlwaysOpen](https://github.com/always-open)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falways-open%2Fsidekick","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falways-open%2Fsidekick","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falways-open%2Fsidekick/lists"}