https://github.com/ikechukwukalu/makeservice
A laravel package for scaffolding Service, Traits, Enums, Facades, Actions, Repository and Interface classes.
https://github.com/ikechukwukalu/makeservice
laravel php
Last synced: 6 months ago
JSON representation
A laravel package for scaffolding Service, Traits, Enums, Facades, Actions, Repository and Interface classes.
- Host: GitHub
- URL: https://github.com/ikechukwukalu/makeservice
- Owner: ikechukwukalu
- License: mit
- Created: 2023-02-23T21:55:43.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-07-01T19:41:06.000Z (about 1 year ago)
- Last Synced: 2025-11-11T15:30:16.062Z (8 months ago)
- Topics: laravel, php
- Language: PHP
- Homepage:
- Size: 63.5 KB
- Stars: 5
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# MAKE SERVICE
[](https://packagist.org/packages/ikechukwukalu/makeservice)
[](https://scrutinizer-ci.com/g/ikechukwukalu/makeservice/)
[](https://www.codefactor.io/repository/github/ikechukwukalu/makeservice)
[](https://security.snyk.io/package/composer/ikechukwukalu%2Fmakeservice)
[](https://github.com/ikechukwukalu/makeservice/actions/workflows/makeservice.yml)
[](https://packagist.org/packages/ikechukwukalu/makeservice)
[](https://github.com/ikechukwukalu/makeservice/blob/main/LICENSE.md)
A laravel package for scaffolding Service, Traits, Enums, Facades, Actions, Repository and Interface classes.
## REQUIREMENTS
- PHP 7.3+
- Laravel 8+
## STEPS TO INSTALL
``` shell
composer require ikechukwukalu/makeservice
```
## SERVICE CLASS
To generate a new service class.
``` shell
php artisan make:service SampleService
php artisan make:service SampleService -f //This will overwrite an existing service class.
```
To generate a new service class for a particular request class.
``` shell
php artisan make:request SampleRequest
php artisan make:service SampleService --request=SampleRequest
```
To generate a service class and a form request class together
```shell
php artisan make:service SampleService --request=SampleRequest -e
```
## TRAIT CLASS
To generate a new trait class.
``` shell
php artisan make:traitclass SampleTrait
php artisan make:traitclass SampleTrait -f //This will overwrite an existing trait class.
```
## ENUM CLASS
To generate a new enum class.
``` shell
php artisan make:enumclass Sample
php artisan make:enumclass Sample -f //This will overwrite an existing enum class.
```
## ACTION CLASS
To generate a new action class.
``` shell
php artisan make:action Sample
php artisan make:action Sample -f //This will overwrite an existing action class.
```
## CONTRACT CLASS
To generate a new contract/interface class.
``` shell
php artisan make:interfaceclass SampleInterface
php artisan make:interfaceclass SampleInterface -f //This will overwrite an existing interface class.
```
## REPOSITORY CLASS
To generate a new repository class for a particular contract/interface class.
``` shell
php artisan make:interfaceclass UserRepositoryInterface --model=User
php artisan make:repository UserRepository --model=User --interface=UserRepositoryInterface
php artisan make:repository UserRepository --model=User --interface=UserRepositoryInterface -f //This will overwrite an existing repository class.
```
To generate extra fetch by user id methods.
``` shell
php artisan make:interfaceclass UserRepositoryInterface --model=User --user
php artisan make:repository UserRepository --model=User --interface=UserRepositoryInterface --user
php artisan make:repository UserRepository --model=User --interface=UserRepositoryInterface --user -f //This will overwrite an existing repository class.
```
To generate a repository class and a contract/interface class together
```shell
php artisan make:repository UserRepository --model=User -c
php artisan make:repository UserRepository --model=User --user -c
```
## FACADE CLASS
To generate a new facade class.
``` shell
php artisan make:facade Sample
php artisan make:facade Sample -f //This will overwrite an existing facade class.
```
To generate a facade class for a repository class
```shell
php artisan make:facade User --contract=UserRepositoryInterface
```
### Bind the contract and the repository class
The last thing we need to do is bind `UserRepository` to `UserRepositoryInterface` in Laravel's Service Container. We will do this via a Service Provider. Create one using the following command:
``` shell
php artisan make:provider RepositoryServiceProvider
```
Open `app/Providers/RepositoryServiceProvider.php` and update the register function to match the following:
``` php
public function register()
{
$this->app->bind(UserRepositoryInterface::class, UserRepository::class);
}
```
Finally, add the new Service Provider to the providers array in `config/app.php`.
``` php
'providers' => [
// ...other declared providers
App\Providers\RepositoryServiceProvider::class,
];
```
### Bind the facade and the action class
If we have a `User` facade class and a `UserService` action class, we would need to add it to Laravel's Service Container. Facades for respository classes will work without any extra binding since they have already been added to the container within the `RepositoryServiceProvider` class, but we would always need to register every facade class we created.
Create the provider:
``` shell
php artisan make:provider FacadeServiceProvider
```
Bind the action class:
``` php
public function register()
{
$this->app->bind('user', UserService::class);
}
```
Register the providers:
``` php
'providers' => [
// ...other declared providers
App\Providers\FacadeServiceProvider::class,
App\Providers\RepositoryServiceProvider::class,
];
```
Finally, add the facade to the aliases array in `config/app.php`.
``` php
'aliases' => Facade::defaultAliases()->merge([
// ...other declared facades
'User' => App\Facades\User::class,
])->toArray(),
```
## LICENSE
The MS package is an open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).