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

ActiveLibrary

andresgarzonj/baserepo
======================

Base repository

v1.0.0(2y ago)09MITPHPPHP ^8.0

Since Jul 17Pushed 2y agoCompare

[ Source](https://github.com/AndresGarzonJ/Laravel-baserepo)[ Packagist](https://packagist.org/packages/andresgarzonj/baserepo)[ RSS](/packages/andresgarzonj-baserepo/feed)WikiDiscussions master Synced 1mo ago

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

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

[](#base-repository-package)

[![master](https://github.com/jsdecena/baserepo/actions/workflows/master.yaml/badge.svg)](https://github.com/jsdecena/baserepo/actions/workflows/master.yaml)[![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)

Sign-up with [Digital Ocean and get $20 discount](https://m.do.co/c/bce94237de96)!
----------------------------------------------------------------------------------

[](#sign-up-with-digital-ocean-and-get-20-discount)

Buy me a [coffeee](https://ko-fi.com/G2G0ADEK) so I can continue development of this package
--------------------------------------------------------------------------------------------

[](#buy-me-a-coffeee-so-i-can-continue-development-of-this-package)

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

[](#how-to-install)

- Run in your terminal `composer require andresgarzonj/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 Andresgarzonj\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($user);
    }

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

        try {

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

            return response()->json($user, 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($user);

        } 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);

            // You can also do this now, so you would not have to instantiate again the repository
            $this->userRepository->update($request->all(), $user);

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

        } 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' => 'User deleted.']);

        } 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()
            ]);
        }
    }

}
```

Testing
=======

[](#testing)

- Run `make test`

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

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% 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

Unknown

Total

1

Last Release

1030d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/639bac9531865f96bcb4bc51899365cdc6f551a5aa14f8243cfeccbe6278c217?d=identicon)[andresgarzonj](/maintainers/andresgarzonj)

---

Top Contributors

[![jsdecena](https://avatars.githubusercontent.com/u/2285625?v=4)](https://github.com/jsdecena "jsdecena (44 commits)")[![AndresGarzonJ](https://avatars.githubusercontent.com/u/26934334?v=4)](https://github.com/AndresGarzonJ "AndresGarzonJ (3 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)")[![kcpal-qode](https://avatars.githubusercontent.com/u/27209774?v=4)](https://github.com/kcpal-qode "kcpal-qode (1 commits)")[![michaelmano](https://avatars.githubusercontent.com/u/8263631?v=4)](https://github.com/michaelmano "michaelmano (1 commits)")[![mikedodd](https://avatars.githubusercontent.com/u/3661077?v=4)](https://github.com/mikedodd "mikedodd (1 commits)")[![NaufalHSyahputra](https://avatars.githubusercontent.com/u/17007647?v=4)](https://github.com/NaufalHSyahputra "NaufalHSyahputra (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

22.8k69.3k](/packages/grumpydictator-firefly-iii)[spatie/fractalistic

A developer friendly wrapper around Fractal

38715.3M8](/packages/spatie-fractalistic)[yajra/laravel-datatables-fractal

Laravel DataTables Fractal Plugin.

966.9M29](/packages/yajra-laravel-datatables-fractal)[tomaj/nette-api

Nette api

36261.8k4](/packages/tomaj-nette-api)[concrete5/core

Concrete core subtree split

19159.3k48](/packages/concrete5-core)

PHPackages © 2026

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