PHPackages                             adityadarma/laravel-service-repository - 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. adityadarma/laravel-service-repository

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

adityadarma/laravel-service-repository
======================================

Create pattern service and repository with easy

1.1.11(2mo ago)1120↓33.3%MITPHPPHP ^8.0

Since Oct 19Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/adityadarma/laravel-service-repository)[ Packagist](https://packagist.org/packages/adityadarma/laravel-service-repository)[ Docs](https://github.com/adityadarma/laravel-service-repository)[ RSS](/packages/adityadarma-laravel-service-repository/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (16)Used By (0)

Service and Repository pattern for laravel!
===========================================

[](#service-and-repository-pattern-for-laravel)

Requirement
-----------

[](#requirement)

- Minimum PHP ^8.0
- Laravel ^9.x

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

[](#installation)

You can install the package via composer for latest version

```
composer require adityadarma/laravel-service-repository
```

Install the base service part of core base service:

```
php artisan service-repository:install
```

Usage
-----

[](#usage)

### \*Service

[](#service)

#### Create service

[](#create-service)

```
php artisan make:service nameService
```

#### Used on controller

[](#used-on-controller)

```
protected NameService $nameService;

public function __construct(
    NameService $nameService
)
{
    $this->nameService = $nameService;
}

public function data()
{
    $this->nameService->functionName()->getData();
}

public function json(Request $request)
{
    $this->nameService->functionName()->toJson();
}

public function withResource(Request $request)
{
    $this->nameService->functionName()->toJsonFromResource(ClassResource::class);
}
```

#### Use Service &amp; Exception

[](#use-service--exception)

Every all exception, must have handle to class CustomException

```
public function nameMethod()
{
    try {
         .........
         if (false) {
            throw new CustomException('Error exception');
         }
        ..........
        // Call toJsonFromResource at controller
        return $this->setData($data)
            ->setMessage('Message data')
            ->setCode(200);
        // OR
        // Call toJson at controller
        return $this->setData($data)
            ->setResource(ClassResource::class)
            ->setMessage('Message data')
            ->setCode(200);
    } catch (Exception $e) {
        return $this->exceptionResponse($e);
    }
}
```

### \*Repository

[](#repository)

#### Create repository

[](#create-repository)

```
php artisan make:repository nameRepository --model
```

- **--model** will create repository with construct model

You can use general function on trait "GeneralFunctionRepository".

#### Used on service

[](#used-on-service)

```
protected NameRepository $nameRepository;

public function __construct(
    NameRepository $nameRepository
)
{
    $this->nameRepository = $nameRepository;
}

public function data()
{
    $this->nameRepository->functionName();
}
```

### \*Request

[](#request)

```
php artisan make:request nameRequest --single
```

- **--single** will make all method to single file request (store, update, delete)

Command request is customized, have failedValidation to consistent API response. I also added an argument, so that we can carry out validation in one FormRequest file. Add function messages to custom response attribute message

### \*Model

[](#model)

```
php artisan make:model name --trait --repository
```

- **--trait** will file trait to use on model like accessor, mutator, relationship and scope
- **--repository** will create file repository with construct model

Command model is customized, we add 2 argument type. You can separate it into traits (accessor, mutator, relationship and scope) and add file repository.

License
-------

[](#license)

This Package is licensed under the MIT license. Enjoy!

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance83

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~61 days

Recently: every ~160 days

Total

15

Last Release

88d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c191e4f4df3ed98299999ab1cf1284ce4b63f1f24ad9f4426b3252f8359fcd15?d=identicon)[adityadarma](/maintainers/adityadarma)

---

Top Contributors

[![adityadarma](https://avatars.githubusercontent.com/u/37822288?v=4)](https://github.com/adityadarma "adityadarma (22 commits)")

---

Tags

laravelrepository patternservice repository patternservice pattern

### Embed Badge

![Health badge](/badges/adityadarma-laravel-service-repository/health.svg)

```
[![Health](https://phpackages.com/badges/adityadarma-laravel-service-repository/health.svg)](https://phpackages.com/packages/adityadarma-laravel-service-repository)
```

###  Alternatives

[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4205.3M84](/packages/livewire-volt)[gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically resolving conflicts between them

341682.2k18](/packages/gehrisandro-tailwind-merge-laravel)[nickurt/laravel-akismet

Akismet for Laravel 11.x/12.x/13.x

97139.6k2](/packages/nickurt-laravel-akismet)[whitecube/laravel-timezones

Store UTC dates in the database and work with custom timezones in the application.

106106.2k](/packages/whitecube-laravel-timezones)[forxer/laravel-gravatar

A library providing easy gravatar integration in a Laravel project.

4235.6k](/packages/forxer-laravel-gravatar)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
