PHPackages                             alirezacrr/lara-artisan-service-maker - 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. alirezacrr/lara-artisan-service-maker

ActiveLibrary

alirezacrr/lara-artisan-service-maker
=====================================

Laravel package for make services or repository and their contracts

v1.0.2(1y ago)010MITPHPPHP ^7.3|^8.0|^8.1|^8.2|^8.3

Since Mar 31Pushed 1y ago1 watchersCompare

[ Source](https://github.com/alirezacrr/lara-artisan-service-maker)[ Packagist](https://packagist.org/packages/alirezacrr/lara-artisan-service-maker)[ RSS](/packages/alirezacrr-lara-artisan-service-maker/feed)WikiDiscussions main Synced 1mo ago

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

Laravel Artisan Service Maker
=============================

[](#laravel-artisan-service-maker)

A Laravel package that provides Artisan commands to generate services, repositories, traits, and interfaces with their contracts. This package helps you implement clean architecture patterns in your Laravel applications with minimal effort.

Features
--------

[](#features)

- Generate service classes with optional interfaces
- Create repository classes with standard CRUD methods
- Generate traits for reusable code
- Create interfaces for your classes
- Automatically bind services and repositories to their interfaces in the service provider
- Support for nested directories

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require alirezacrr/lara-artisan-service-maker
```

The package will automatically register its service provider.

Usage
-----

[](#usage)

### Creating a Service

[](#creating-a-service)

```
php artisan make:service UserService
```

Options:

- `--interface` or `-i`: Create an interface for this service
- `--model=ModelName` or `-m ModelName`: The model that the service will use
- `--bind` or `-b`: Automatically bind the service in the service provider
- `--singleton` or `-s`: Register the service as a singleton

Example with all options:

```
php artisan make:service UserService -i -m User -b -s
```

This will create:

- `app/Services/UserService.php`
- `app/Interfaces/UserServiceInterface.php` (if `-i` option is used)
- Add binding in `AppServiceProvider.php` (if `-b` or `-s` option is used)

### Creating a Repository

[](#creating-a-repository)

```
php artisan make:repository UserRepository
```

Options:

- `--model=ModelName`: The model that the repository will use (defaults to the repository name)
- `--interface` or `-i`: Create an interface for this repository
- `--bind` or `-b`: Automatically bind the repository in the service provider
- `--singleton` or `-s`: Register the repository as a singleton

Example:

```
php artisan make:repository UserRepository --model=User -i -b
```

This will create:

- `app/Repositories/UserRepository.php` with standard CRUD methods
- `app/Interfaces/UserRepositoryInterface.php` (if `-i` option is used)
- Add binding in `AppServiceProvider.php` (if `-b` or `-s` option is used)

### Creating a Trait

[](#creating-a-trait)

```
php artisan make:trait Filterable
```

This will create `app/Traits/Filterable.php`.

### Creating an Interface

[](#creating-an-interface)

```
php artisan make:interface Searchable
```

This will create `app/Interfaces/SearchableInterface.php`.

### Nested Directories

[](#nested-directories)

All commands support nested directories:

```
php artisan make:service Admin/UserService
php artisan make:repository User/OrderRepository
php artisan make:trait Concerns/Filterable
php artisan make:interface Contracts/Searchable
```

Examples
--------

[](#examples)

### Service with Interface and Model

[](#service-with-interface-and-model)

```
php artisan make:service UserService -i -m User
```

Creates:

```
// app/Interfaces/UserServiceInterface.php
