{"id":23453818,"url":"https://github.com/elsayed85/laravel-microservices-redis","last_synced_at":"2025-04-10T23:53:41.332Z","repository":{"id":193692890,"uuid":"689324345","full_name":"elsayed85/laravel-microservices-redis","owner":"elsayed85","description":"Build Your MicroService App With Laravel \u0026 Redis","archived":false,"fork":false,"pushed_at":"2024-07-08T07:37:29.000Z","size":85,"stargazers_count":0,"open_issues_count":4,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T23:53:38.538Z","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/elsayed85.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"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}},"created_at":"2023-09-09T12:58:13.000Z","updated_at":"2023-09-09T16:31:36.000Z","dependencies_parsed_at":"2024-01-01T09:00:42.037Z","dependency_job_id":"c6a39349-979c-44fd-ae5f-d56fb773dd2d","html_url":"https://github.com/elsayed85/laravel-microservices-redis","commit_stats":null,"previous_names":["elsayed85/laravel-microservices-redis"],"tags_count":0,"template":true,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elsayed85%2Flaravel-microservices-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elsayed85%2Flaravel-microservices-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elsayed85%2Flaravel-microservices-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elsayed85%2Flaravel-microservices-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elsayed85","download_url":"https://codeload.github.com/elsayed85/laravel-microservices-redis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248317704,"owners_count":21083528,"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-12-24T02:29:58.009Z","updated_at":"2025-04-10T23:53:41.316Z","avatar_url":"https://github.com/elsayed85.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Development\n\n### clone the repo\n\nclick on Use This Template and create new Repo\n\nthen clone the repo\n\n```bash\ngit clone https://github.com/{yourGithubUser}/laravel-microservices-redis.git\n```\n\n### install the dependencies\n\n```bash\ncomposer install\n```\n\n### Create New Service\n\n```bash\nphp artisan make:service {service_name}\n```\n\nExample :\n\n```bash\nphp artisan make:service Product\n```\n\nThis will create src\\Services\\ProductService and this folders will be created by default\n\n```bash\nsrc\n├── Services\n    └── ProductService\n        ├── DTO\n        │   └── ProductData.php\n        ├── Enum\n        │   └── ProductEvent.php\n        ├── Event\n        │   └── ProductCreatedEvent.php\n        │   └── ProductUpdatedEvent.php\n        │   └── ProductDeletedEvent.php\n        ├── ProductRedisService.php\n```\n\n# Installation On Each Service\n\nYou can install the package via composer:\n\n```bash\ncomposer require elsayed85/lms-redis \"@dev\"\n```\n\n## Fast Installation\n\n```bash\nphp artisan lms:install\n```\n\n## Manual Installation\n\n### Config File [Required]\n\nYou Must publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"lms-redis-config\"\n```\n\nThis is the contents of the published config file:\n\n```php\n\u003c?php\n\nreturn [\n    'service' =\u003e \\Elsayed85\\LmsRedis\\LmsRedis::class,\n\n     'redis' =\u003e [\n        'client' =\u003e 'phpredis',\n\n        'options' =\u003e [\n            'cluster' =\u003e 'redis',\n            'prefix' =\u003e 'database_',\n        ],\n\n        'default' =\u003e [\n            'url' =\u003e null,\n            'host' =\u003e '127.0.0.1',\n            'username' =\u003e null,\n            'password' =\u003e null,\n            'port' =\u003e '6379',\n            'database' =\u003e '0',\n        ],\n\n        'cache' =\u003e [\n            'url' =\u003e null,\n            'host' =\u003e '127.0.0.1',\n            'username' =\u003e null,\n            'password' =\u003e null,\n            'port' =\u003e '6379',\n            'database' =\u003e '1',\n        ],\n    ],\n];\n```\n\nReplace the service with the project redis service class (Created For You) [Example : ProductRedisService::class]\n\n### Consume Command [Optional]\n\nAlso You Must Publish The Consume Command If You want To Handel The Incoming Redis Stream Events\n\n```bash\nphp artisan vendor:publish --tag=\"lms-redis-consume-command\"\n```\n\nNOTE : You need to schedule function in App\\Console\\Kernel.php\n\n```php\nprotected function schedule(Schedule $schedule)\n{\n    $schedule-\u003ecommand('lms:consume')-\u003eeveryMinute();\n}\n```\n\n## Usage\n\n#### Extend The Service Class [Fast Installation Do that for you]\n\n```php\n\u003c?php\n\nnamespace app\\Services;\n\nuse Elsayed85\\LmsRedis\\Services\\ProductService as BaseRedisService;\nuse Elsayed85\\LmsRedis\\Services\\ProductService\\Event\\ProductCreatedEvent;\nuse Elsayed85\\LmsRedis\\Services\\ProductService\\DTO\\ProductData;\n\nclass ProductService extends BaseRedisService\n{\n    public function publishProductCreated(ProductData $data): void\n    {\n        $this-\u003epublish(new ProductCreatedEvent($data));\n    }\n}\n\n```\n\n### Creating Actions\n\n```php\n\u003c?php\n\nnamespace App\\Actions;\n\nuse App\\Models\\Category;\nuse App\\Models\\Product;\nuse App\\Services\\ProductService;\n\nclass CreateProductAction\n{\n    public function __construct(private readonly ProductService $redis)\n    {\n    }\n\n    public function execute(string $name, string $description, float $price): Product\n    {\n        $product = Product::create([\n            'name' =\u003e $name,\n            'description' =\u003e $description,\n            'price' =\u003e $price\n        ]);\n\n        $this-\u003eredis-\u003epublishProductCreated(\n            $product-\u003etoData(),\n        );\n\n        return $product;\n    }\n}\n```\n\n#### ADD toData() function to your model\n\n```php\nuse Elsayed85\\LmsRedis\\Services\\ProductService\\DTO\\ProductData;\n\nclass Product extends Model\n{\n    use HasFactory;\n\n    public function toData(): ProductData\n    {\n        return new ProductData(\n            id : $this-\u003eid,\n            name : $this-\u003ename,\n            description : $this-\u003edescription,\n            price : $this-\u003eprice,\n        );\n    }\n}\n```\n\n### AddAction To Controller\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Controllers;\n\nuse App\\Actions\\CreateProductAction;\nuse App\\Http\\Requests\\StoreProductRequest;\n\nclass ProductController extends Controller\n{\n    public function store(StoreProductRequest $request, CreateProductAction $createProduct)\n    {\n        $product = $createProduct-\u003eexecute(\n            $request-\u003egetName(),\n            $request-\u003egetDescription(),\n            $request-\u003egetPrice()\n        );\n\n        return response([\n            'data' =\u003e $product-\u003etoData()\n        ], Response::HTTP_CREATED);\n    }\n}\n```\n\n### Add Api Endpoint To Routes\n\n```php\n\u003c?php\nuse App\\Http\\Controllers\\ProductController;\n\nRoute::post('/v1/products', [ProductController::class, 'store']);\n```\n\nAnd That's It!\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- [Elsayed Kamal](https://github.com/elsayed85)\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%2Felsayed85%2Flaravel-microservices-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felsayed85%2Flaravel-microservices-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felsayed85%2Flaravel-microservices-redis/lists"}