An open API service indexing awesome lists of open source software.

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

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.

![Descripción de la imagen](https://i.ibb.co/XtzQRsJ/Pizarra-Mapa-de-Web-Lluvia-de-Ideas-Negro-Naranja-Moderno-Profesional.png)

## 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;
}
}

````