PHPackages                             jake142/laravel-service - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jake142/laravel-service

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jake142/laravel-service
=======================

A package to split a laravel project into smaller services

v3.1.0(1mo ago)612.3k2[1 PRs](https://github.com/jake142/laravel-service/pulls)MITPHP

Since Sep 17Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/jake142/laravel-service)[ Packagist](https://packagist.org/packages/jake142/laravel-service)[ RSS](/packages/jake142-laravel-service/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (2)Versions (35)Used By (0)

Laravel Service
---------------

[](#laravel-service)

A package to divide Laravel into smaller services. Then main goal of this package is:

1. Readable, the code is split into services
2. Scalable, run services as needed
3. Faster development, split work between developers

#### Installation

[](#installation)

Simply run:

> composer require jake142/laravel-service

#### Usage

[](#usage)

Start by running

> php artisan laravel-service:make

This will start a setup wizard where you define:

1. The name of the service
2. The version of the service (eg. V1)
3. If you want a sample controller (recommended)
4. If you want a sample job (recommended)
5. If you want a sample test (recommended)

The service files are created under `Services/{version}/{name}/` but the service is **not** enabled yet. Your root `composer.json` is **not** modified by `make` (see release notes 3.1.0).

#### Enable a service

[](#enable-a-service)

To enable a service run:

> php artisan laravel-service:enable laravel-service/$version-$service (eg. laravel-service/v1-sampleservice)

Use the lowercase package name (`laravel-service/v1-sampleservice`), not the folder path.

This will enable the service which means:

1. Registers the path repository in your root `composer.json` (if not already registered)
2. Composer runs `require` on your service
3. The tests will be added to the phpunit.xml and therefore able to run with the phpunit command

If the service exists on disk under `Services/` but is not yet in `composer.json` (for example after merging a branch), `enable` will register it automatically before requiring it.

#### Working across git branches

[](#working-across-git-branches)

Service **code** lives in `Services/` and follows your git branches. Composer and PHPUnit state live in the host app and are shared locally between checkouts.

Recommended workflow:

1. On a feature branch (e.g. sandbox): `php artisan laravel-service:make` and commit the new `Services/...` folder.
2. Merge that branch into the branch where you want the service (e.g. master).
3. On the target branch: `php artisan laravel-service:enable laravel-service/v1-myservice` (no need to run `make` again).
4. After switching branches, run `php artisan laravel-service:sync` (normalizes constraints and updates path packages), or `composer install` if you only need to match `composer.lock`.

#### Sync after branch switch

[](#sync-after-branch-switch)

> php artisan laravel-service:sync

Path packages resolve to `dev-{branch}` (e.g. `dev-main`, `dev-sandbox`). This command rewrites all `laravel-service/*` constraints to `@dev` and runs `composer update laravel-service/*`, so you do not need manual edits to root `composer.json` when switching branches.

#### Disable a service

[](#disable-a-service)

To disable a service run:

> php artisan laravel-service:disable laravel-service/$version-$service (eg. laravel-service/v1-sampleservice)

This will disable the service which means:

1. Composer runs remove on your service
2. The tests will be removed from the phpunit.xml

#### List services and their status

[](#list-services-and-their-status)

> php artisan laravel-service:list

#### Generic Queues and Jobs

[](#generic-queues-and-jobs)

To call the generic queue:

```
(new GenericQueue('Services\\V1\\Test\\Jobs\\ExampleJob', ['param'=>'test'], $queue = null))->dispatch();
```

To run the generic job:

```
