ins0mniac/service-generator

The package provide commands for generating services and interfaces and registering them in the dependency container

v1.0.0 2022-03-25 08:34 UTC

This package is not auto-updated.

Last update: 2025-08-09 23:08:18 UTC


README

Laravel Service generator for Laravel applications

Introduction

Service generator provides commands to create services, interfaces and providers and register the dependencies in the dependency container.

With this package, you can generate new files (services, interfaces and providers) only with "artisan" command just as controllers creation. It is not necessary to list the provider in app.php file. The process of listing providers in app.php and registering the dependencies in the providers is automated.

The list of the available commands are shown below:

Features

  • Laravel >= v8.0 are supported;
  • Easy setup, no additional configuration;
  • Easy to use;
  • It's made only to facilitate the work of developers;
  • Free and always be free.

Official Documentation

Installation

You can install this package via Composer by running this command:

composer require ins0mniac/service-generator

NOTE : The package will automatically register itself.

Commands

For services creating:

Plain service

You can generate plain service (php file) with :

$ php artisan create:service NameOfTheService

If you don't specify the name of the service, Laravel will ask you to type it.

$ php artisan create:service

With this command, Laravel will generate new file with all the necessary attributes as namespace, class name, etc. The file will be generated in Services/* directory (based of the name of the service), so if you type service name as Users/User, the service file will be located in Services/Users with name of UserService.

Service with implementation

You can generate service which implements interface:

class NameOfTheService impements NameOfTheInterface

$ php artisan create:service NameOfTheService --interface NameOfTheInterface

or just

$ php artisan create:service --interface

If you don't specify name of the service and/or interface, Laravel will ask you for them.

After you type the interface name, Laravel will ask you if you want to register dependency in the container. If you want to register it, just type y and enter the name of the Provider (if provider didn't exists, the command will create new one and publish it in app.php). After entering the provider name, you should specify the type of the registering - bind or singleton.

NOTE : This command will create new service file, so if you shouldn't type name of the existing file!

In the end of the generation process you will have:

  • New Service class (new file);
  • Service class that implements new or existing Interface;
  • Registered dependency in new or existing Provider;

For interfaces creating:

Interface only

You can generate only interface (php file) with :

$ php artisan create:interface NameOfTheInterface

If you don't specify the name of the interface, Laravel will ask you to type it.

$ php artisan create:interface

Generate interface and implement it from new or existing service

You can generate interface and implement it:

class NameOfTheService impements NameOfTheInterface

$ php artisan create:interface NameOfTheInterface --service NameOfTheService

or just

$ php artisan create:interface --service

If you don't specify name of the interface and/or service, Laravel will ask you for them.

After you type the interface name, Laravel will ask you if you want to register dependency in the container. If you want to register it, just type y and enter the name of the Provider (if provider didn't exists, the command will create new one and publish it in app.php). After entering the provider name, you should specify the type of the registering - bind or singleton.

In the end of the generation process you will have:

  • Service class that implements new or existing Interface;
  • Registered dependency in new or existing Provider;

For provider creating:

Provider only

You can generate only provider (php file) with :

$ php artisan create:provider NameOfTheProvider

If you don't specify the name of the provider, Laravel will ask you to type it.

$ php artisan create:provider

Generate or get existing provider and register dependency in it

You can generate or get existing provider:

$ php artisan create:provider NameOfTheProvider --register

or just

$ php artisan create:provider --register

If you don't specify name, Laravel will ask you for them.

After you type the provider name, Laravel will ask you for the names of service and interface and the type of the registering - bind or singleton.

In the end of the generation process you will have:

  • Service class that implements new or existing Interface;
  • Registered dependency in new or existing Provider;

Examples of generated files

Coming soon

The next stage will be adding --resource option to create:service and create:interface commands. This will allow you to generate files with resource methods - getAll(), findByKey(Model $model), etc.

License

Laravel Service Generator is open-sourced software licensed under the MIT license.