{"id":18150944,"url":"https://github.com/foxws/laravel-algos","last_synced_at":"2025-04-28T17:28:51.022Z","repository":{"id":260349637,"uuid":"880787270","full_name":"foxws/laravel-algos","owner":"foxws","description":"Create algorithms (algos) for your Laravel application.","archived":false,"fork":false,"pushed_at":"2025-04-23T18:58:15.000Z","size":38,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-23T19:47:16.918Z","etag":null,"topics":["actions","algorithms","algos","foxws","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/foxws.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","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,"zenodo":null},"funding":{"github":"Foxws"}},"created_at":"2024-10-30T11:06:03.000Z","updated_at":"2025-04-23T18:58:19.000Z","dependencies_parsed_at":"2024-10-30T21:25:14.225Z","dependency_job_id":"fe59b0f7-1caa-4531-9817-d586763c02e0","html_url":"https://github.com/foxws/laravel-algos","commit_stats":null,"previous_names":["foxws/laravel-algos"],"tags_count":5,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxws%2Flaravel-algos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxws%2Flaravel-algos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxws%2Flaravel-algos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxws%2Flaravel-algos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foxws","download_url":"https://codeload.github.com/foxws/laravel-algos/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251354826,"owners_count":21576241,"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":["actions","algorithms","algos","foxws","laravel"],"created_at":"2024-11-02T01:05:55.271Z","updated_at":"2025-04-28T17:28:51.016Z","avatar_url":"https://github.com/foxws.png","language":"PHP","funding_links":["https://github.com/sponsors/Foxws"],"categories":[],"sub_categories":[],"readme":"# Laravel Algos\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/foxws/laravel-algos.svg?style=flat-square)](https://packagist.org/packages/foxws/laravel-algos)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/foxws/laravel-algos/run-tests.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/foxws/laravel-algos/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/foxws/laravel-algos/fix-php-code-style-issues.yml?branch=main\u0026label=code%20style\u0026style=flat-square)](https://github.com/foxws/laravel-algos/actions?query=workflow%3A\"Fix+PHP+code+style+issues\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/foxws/laravel-algos.svg?style=flat-square)](https://packagist.org/packages/foxws/laravel-algos)\n\nThis package can be used to create algorithms (algos) for your Laravel application.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require foxws/laravel-algos\n```\n\n## Usage\n\nGenerate an `Algo` class (you may also use `php artisan make:algo MyAlgo`):\n\n```php\nuse Foxws\\Algos\\Algos\\Algo;\nuse Foxws\\Algos\\Algos\\Result;\nuse Foxws\\Algos\\Tests\\Models\\Post;\nuse Foxws\\Algos\\Tests\\Models\\User;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Str;\n\nclass GenerateUserFeed extends Algo\n{\n    protected ?User $user = null;\n\n    public function handle(): Result\n    {\n        $hash = $this-\u003egenerateUniqueId();\n\n        cache()-\u003eset(\n            $this-\u003egenerateUniqueId(),\n            ['ids' =\u003e (array) $this-\u003egetCollection()],\n            now()-\u003eaddMinutes(10),\n        );\n\n        return $this\n            -\u003esuccess('Feed generated successfully')\n            -\u003ewith('hash', $hash);\n    }\n\n    public function model(User $user): self\n    {\n        $this-\u003euser = $user;\n\n        return $this;\n    }\n\n    protected function getCollection(): Collection\n    {\n        return Post::query()\n            -\u003eselect('id')\n            -\u003ewhere('user_id', $this-\u003euser-\u003egetKey())\n            -\u003einRandomOrder()\n            -\u003etake(5)\n            -\u003eget();\n    }\n\n    protected function generateUniqueId(): string\n    {\n        return Str::ulid();\n    }\n}\n```\n\nTo run the algorithm:\n\n```php\n$algo = GenerateUserFeed::make()-\u003emodel($user)-\u003erun();\n\n// $algo-\u003estatus; // success, failed, skipped\n// $algo-\u003emessage; // reason\n// $algo-\u003emeta; // array of metadata\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](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- [francoism90](https://github.com/foxws)\n- [All Contributors](../../contributors)\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%2Ffoxws%2Flaravel-algos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoxws%2Flaravel-algos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoxws%2Flaravel-algos/lists"}