PHPackages                             serefercelik/baserepo - 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. serefercelik/baserepo

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

serefercelik/baserepo
=====================

Base repository

v1.0.8(5y ago)07MITPHPPHP ^7.1.3

Since Jul 16Pushed 5y agoCompare

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

READMEChangelog (1)Dependencies (4)Versions (11)Used By (0)

Base Repository Package
=======================

[](#base-repository-package)

[![Build Status](https://camo.githubusercontent.com/51d6480ca40ff88c2e44181d61dfdfbe192306b5a30e1bf45f61a661cd55ee82/68747470733a2f2f7472617669732d63692e6f72672f6a73646563656e612f626173657265706f2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jsdecena/baserepo)[![Latest Stable Version](https://camo.githubusercontent.com/f41ad0a3ba5d2931890ce9f14fd2e6a24a320792cf376d9c5c1bd9c391ff9dce/68747470733a2f2f706f7365722e707567782e6f72672f6a73646563656e612f626173657265706f2f762f737461626c65)](https://packagist.org/packages/jsdecena/baserepo)[![Total Downloads](https://camo.githubusercontent.com/36b21f06a1d8b7fdc5cac77574df4b0654ac9b4d091d6ad817bbad7308b6a0c3/68747470733a2f2f706f7365722e707567782e6f72672f6a73646563656e612f626173657265706f2f646f776e6c6f616473)](https://packagist.org/packages/jsdecena/baserepo)[![License](https://camo.githubusercontent.com/64e61e5197139ce67f5733a6cae2b83e9dd123f505f442851d2476a9f8c8a76e/68747470733a2f2f706f7365722e707567782e6f72672f6a73646563656e612f626173657265706f2f6c6963656e7365)](https://packagist.org/packages/jsdecena/baserepo)[![FOSSA Status](https://camo.githubusercontent.com/6738e28a1d2f7d2e396e21f88a6f7cf4a320932c2d2664a9a4d0522046d7f3e2/68747470733a2f2f6170702e666f7373612e696f2f6170692f70726f6a656374732f6769742532426769746875622e636f6d2532466a73646563656e61253246626173657265706f2e7376673f747970653d736869656c64)](https://app.fossa.io/projects/git%2Bgithub.com%2Fjsdecena%2Fbaserepo?ref=badge_shield)

#### Base repository is used by [Laracom](https://github.com/Laracommerce/laracom) under the hood

[](#base-repository-is-used-by-laracom-under-the-hood)

How to install
--------------

[](#how-to-install)

- Run in your terminal `composer require jsdecena/baserepo`
- In your repository class, extend it so you can use the methods readily available.

```
namespace App\Repositories;

use App\User;
use Illuminate\Http\Request;
use Illuminate\Database\QueryException;
use Jsdecena\Baserepo\BaseRepository;

class UserRepository extends BaseRepository {

    public function __construct(User $user)
    {
        parent::__construct($user);
    }

    public function createUser(array $data) : User
    {
        try {
            return $this->create($data);
        } catch (QueryException $e) {
            throw new \Exception($e);
        }
    }
}
```

- Then, use it in your controller.

```
use App\Http\Controllers\Controller;
use App\Repositories\UserRepository;
use App\User;

class MyController extends Controller {

    private $userRepository;

    /**
    *
    * Inject your repository or the interface here
    */
    public function __construct(UserRepository $userRepository)
    {
        $this->userRepository = $userRepository;
    }

    public function index()
    {
        $user = $this->userRepository->all();

        return response()->json($data);
    }

    public function store(Request $request)
    {
        // do data validation

        try {

            $user = $this->userRepository->createUser($request->all());

            return response()->json($data, 201);

        } catch (Illuminate\Database\QueryException $e) {

            return response()->json([
                'error' => 'user_cannot_create',
                'message' => $e->getMessage()
            ]);
        }
    }

    public function show($id)
    {
        // do data validation

        try {

            $user = $this->userRepository->findOneOrFail($id);

            return response()->json($data);

        } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {

            return response()->json([
                'error' => 'user_no_found',
                'message' => $e->getMessage()
            ]);
        }
    }

    public function update(Request $request, $id)
    {
        // do data validation

        try {

            $user = $this->userRepository->findOneOrFail($id);

            // Create an instance of the repository again
            // but now pass the user object.
            // You can DI the repo to the controller if you do not want this.
            $userRepo = new UserRepository($user);
            $userRepo->update($request->all())

            return response()->json($data);

        } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {

            return response()->json([
                'error' => 'user_no_found',
                'message' => $e->getMessage()
            ]);

        } catch (Illuminate\Database\QueryException $e) {

            return response()->json([
                'error' => 'user_cannot_update',
                'message' => $e->getMessage()
            ]);
        }
    }

    public function destroy($id)
    {
        // do data validation

        try {

            $user = $this->userRepository->findOneOrFail($id);

            // Create an instance of the repository again
            // but now pass the user object.
            // You can DI the repo to the controller if you do not want this.
            $userRepo = new UserRepository($user);
            $userRepo->delete()

            return response()->json($data);

        } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {

            return response()->json([
                'error' => 'user_no_found',
                'message' => $e->getMessage()
            ]);

        } catch (Illuminate\Database\QueryException $e) {

            return response()->json([
                'error' => 'user_cannot_delete',
                'message' => $e->getMessage()
            ]);
        }
    }

}
```

Author
======

[](#author)

[Jeff Simons Decena](https://jsdecena.me)

License
-------

[](#license)

[![FOSSA Status](https://camo.githubusercontent.com/e1b3e3dd93bcdd840c4fb81e2b13ead6097dc2c4847d23b8c82aa7b9e699359e/68747470733a2f2f6170702e666f7373612e696f2f6170692f70726f6a656374732f6769742532426769746875622e636f6d2532466a73646563656e61253246626173657265706f2e7376673f747970653d6c61726765)](https://app.fossa.io/projects/git%2Bgithub.com%2Fjsdecena%2Fbaserepo?ref=badge_large)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 78.1% 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 ~90 days

Recently: every ~105 days

Total

9

Last Release

2132d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/424ad2974c32337e197acb70f17b61d09308ea022aee401591507e48e21a1602?d=identicon)[serefercelik](/maintainers/serefercelik)

---

Top Contributors

[![jsdecena](https://avatars.githubusercontent.com/u/2285625?v=4)](https://github.com/jsdecena "jsdecena (25 commits)")[![Faks](https://avatars.githubusercontent.com/u/1909645?v=4)](https://github.com/Faks "Faks (2 commits)")[![fossabot](https://avatars.githubusercontent.com/u/29791463?v=4)](https://github.com/fossabot "fossabot (1 commits)")[![edwinwongnetccentric](https://avatars.githubusercontent.com/u/27198513?v=4)](https://github.com/edwinwongnetccentric "edwinwongnetccentric (1 commits)")[![michaelmano](https://avatars.githubusercontent.com/u/8263631?v=4)](https://github.com/michaelmano "michaelmano (1 commits)")[![NaufalHSyahputra](https://avatars.githubusercontent.com/u/17007647?v=4)](https://github.com/NaufalHSyahputra "NaufalHSyahputra (1 commits)")[![serefercelik](https://avatars.githubusercontent.com/u/12779444?v=4)](https://github.com/serefercelik "serefercelik (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/serefercelik-baserepo/health.svg)

```
[![Health](https://phpackages.com/badges/serefercelik-baserepo/health.svg)](https://phpackages.com/packages/serefercelik-baserepo)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9446.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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