https://github.com/joseangelcrn/artisan_service_repository_generator
You can automatically create files that follow the service-repository pattern by adding custom commands to Laravel, such as php artisan make:repository and php artisan make:service
https://github.com/joseangelcrn/artisan_service_repository_generator
artisan artisan-command artisan-commands automation best-practices clean-code clean-code-architecture code-generation code-generator laravel laravel-framework laravel-package open-source package packagist php repository-pattern scalable-architecture service-pattern service-repository-pattern
Last synced: 3 months ago
JSON representation
You can automatically create files that follow the service-repository pattern by adding custom commands to Laravel, such as php artisan make:repository and php artisan make:service
- Host: GitHub
- URL: https://github.com/joseangelcrn/artisan_service_repository_generator
- Owner: joseangelcrn
- License: mit
- Created: 2024-12-20T14:53:22.000Z (5 months ago)
- Default Branch: master
- Last Pushed: 2025-01-16T11:42:13.000Z (4 months ago)
- Last Synced: 2025-01-16T12:56:08.097Z (4 months ago)
- Topics: artisan, artisan-command, artisan-commands, automation, best-practices, clean-code, clean-code-architecture, code-generation, code-generator, laravel, laravel-framework, laravel-package, open-source, package, packagist, php, repository-pattern, scalable-architecture, service-pattern, service-repository-pattern
- Language: PHP
- Homepage:
- Size: 139 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Laravel Service-Repository Generator
This package provides artisan commands to easily generate **Services** and **Repositories**, following the **Service-Repository Pattern**, which are not natively supported in Laravel. It helps developers maintain a clean and scalable code structure.
The code is designed so that any developer can build upon it, as it follows best practices and clean code principles.

## Features
- Generate repository and service classes with a single command.
- Adheres to the Service-Repository Pattern.
- Automatically binds repositories to interfaces in the Laravel service container.
- Customizable templates for your own conventions.## Requirements
- PHP 8.0 - 8.4
- Composer
- nette/php-generator >= 4.1## Packagist Page
https://packagist.org/packages/josanangel/service-repository-manager## Installation
### Install the package via Composer:
```bash
composer require josanangel/service-repository-manager
```## After install
### Add the following service provider to your ``bootstrap/providers.php`` file:
````php
## Examples
### Create a UserRepository file
```bash
php artisan make:repository User
```
### Content````php
model to your model in order to repository works successfully
* ... e.g.: $this->model = User::class;
*/
public function __construct()
{
}public function all()
{
return $this->model->all();
}public function create($data)
{
return $this->model->create($data);
}public function find($id)
{
return $this->model->find($id);
}public function update($id, $data)
{
return $this->model->where("id",$id)->update($data);
}public function delete($id)
{
return $this->model->where("id",$id)->delete();
}
}````
### Create a UserService file
```bash
php artisan make:service User
```
### Output````php
### Create a UserService file with injected dependencies
#### UserService + [ _injected_ ] AuthService
```bash
php artisan make:service User --services=auth
```
#### Output````php
authService = $authService;
}
}````
````php#### UserService + [ _injected_ ] AuthService + [ _injected_ ] MapService + [ _injected_ ] UserRepository
```bash
php artisan make:service User --services=auth,map --repositories=auth
```
### Output````php
authRepository = $authRepository;
$this->authService = $authService;
$this->mapService = $mapService;
}
}````
#### UserService + [ _injected_ ] UserRepository with CRUD methods```bash
php artisan make:service User --repositories-crud=User
```````php
model->all();
}public function store($data)
{
$this->model->create($data);
}public function show($id)
{
$this->model->findById($id);
}public function update($id, $data)
{
$this->model->where("id",$id)->update($data);
}public function destroy($id)
{
$this->model->where("id",$id)->delete();
}
}
````````php
userRepository = $userRepository;
}
}````