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(4mo ago)1144↓78.3%MITPHPPHP ^8.0

Since Oct 19Pushed 4mo 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 2d 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

41

—

FairBetter than 87% of packages

Maintenance75

Regular maintenance activity

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

135d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/37822288?v=4)[Aditya Darma](/maintainers/adityadarma)[@adityadarma](https://github.com/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

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

23.9k69.5k](/packages/grumpydictator-firefly-iii)[firefly-iii/data-importer

Firefly III Data Import Tool.

8035.8k](/packages/firefly-iii-data-importer)[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[ronasit/laravel-helpers

Provided helpers function and some helper class.

2085.6k31](/packages/ronasit-laravel-helpers)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1320.9k4](/packages/team-nifty-gmbh-tall-datatables)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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