PHPackages                             lara-pack/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. [Framework](/categories/framework)
4. /
5. lara-pack/repository

ActiveLibrary[Framework](/categories/framework)

lara-pack/repository
====================

Laravel Repository Concept

v1.0.0(8mo ago)023MITPHP

Since Aug 19Pushed 2mo agoCompare

[ Source](https://github.com/bhagaskara/lara-pack-repository)[ Packagist](https://packagist.org/packages/lara-pack/repository)[ RSS](/packages/lara-pack-repository/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Laravel Repository Concept (lara-pack/repository)
=================================================

[](#laravel-repository-concept-lara-packrepository)

A minimal structured repository pattern concept package for Laravel, providing a flexible `MasterDataRepository` class to handle common CRUD actions, complex `where` clauses, and dynamic queries for your models.

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

[](#installation)

You can install the package via composer:

```
composer require lara-pack/repository
```

*(Note: Ensure your package repository is configured locally or the package is published on Packagist)*

Usage
-----

[](#usage)

Create a new repository class and extend `LaraPack\Repository\MasterDataRepository`.

Implement the `className()` method which should return the eloquent `Model` class name this repository handles.

### 1. Creating a Repository

[](#1-creating-a-repository)

```
namespace App\Repositories;

use LaraPack\Repository\MasterDataRepository;
use App\Models\User;

class UserRepository extends MasterDataRepository
{
    protected static function className(): string
    {
        return User::class;
    }
}
```

### 2. Available Methods

[](#2-available-methods)

Here are the various methods you can use out of the box with `MasterDataRepository`.

#### `all()`

[](#all)

Retrieves all records.

```
$users = UserRepository::all();
```

#### `find($id)`

[](#findid)

Finds a specific record by its primary key.

```
$user = UserRepository::find(1);
```

#### `create($data)`

[](#createdata)

Creates a new record.

```
$user = UserRepository::create([
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'password' => bcrypt('password')
]);
```

#### `update($id, $data)`

[](#updateid-data)

Updates a record by its primary key.

```
$status = UserRepository::update(1, ['name' => 'Jane Doe']);
```

#### `delete($id)`

[](#deleteid)

Deletes a record (or soft deletes if the model uses the `SoftDeletes` trait).

```
$status = UserRepository::delete(1);
```

#### `forceDelete($id)`

[](#forcedeleteid)

Permanently deletes a record bypassing soft deletes.

```
$status = UserRepository::forceDelete(1);
```

### 3. Dynamic Filtering (`getBy`, `findBy`, `countBy`, `updateBy`, `deleteBy`, `forceDeleteBy`)

[](#3-dynamic-filtering-getby-findby-countby-updateby-deleteby-forcedeleteby)

The true power of this repository package is its `whereClause` processing. You can dynamically pass arrays of conditions.

#### Structure of Where Clause

[](#structure-of-where-clause)

Each clause is an array structure that follows this format:

- Basic condition: `['column', 'value']` (operator defaults to `=`)
- With specified operator: `['column', 'operator', 'value']`
- With `IN` operator: `['column', ['value1', 'value2']]`
- With `OR` conjunction: `['column', 'operator', 'value', 'OR']`

#### Retrieve a single record (`findBy`)

[](#retrieve-a-single-record-findby)

```
// Find the first user where name = 'John'
$user = UserRepository::findBy([
    ['name', '=', 'John']
]);

// You can request a "lock for update" on the row by passing true as the 2nd argument:
$lockedUser = UserRepository::findBy([['id', 1]], true);
```

#### Retrieve multiple records (`getBy`)

[](#retrieve-multiple-records-getby)

```
// Getting users where status is active AND role IN (admin, manager)
// Order by created_at DESC
$users = UserRepository::getBy(
    [
        ['status', 'active'], // omitted operator defaults to '='
        ['role', ['admin', 'manager']], // using an array as value defaults to 'IN'
    ],
    [
        ['created_at', 'DESC'] // Order by clause
    ]
);

// Advanced conditions (Using OR)
$users = UserRepository::getBy([
    ['role', 'admin'],
    ['status', '=', 'banned', 'OR'] // Will map to OR WHERE status = 'banned'
]);
```

#### Count records (`count()`, `countBy()`)

[](#count-records-count-countby)

```
$totalUsers = UserRepository::count();

$activeUsersCount = UserRepository::countBy([
    ['status', 'active']
]);
```

#### Update or Delete based on conditions

[](#update-or-delete-based-on-conditions)

```
// Update all users where status = 'pending'
UserRepository::updateBy([['status', 'pending']], ['status' => 'active']);

// Delete all users where status = 'banned'
UserRepository::deleteBy([['status', 'banned']]);

// Force delete users based on condition
UserRepository::forceDeleteBy([['status', 'banned']]);
```

Contributing
------------

[](#contributing)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License
-------

[](#license)

[MIT](https://choosealicense.com/licenses/mit/)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance74

Regular maintenance activity

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

264d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/63814bcebe20646b82976951817f1210b6c06138037b49772b844af9a876116c?d=identicon)[bhagaskara](/maintainers/bhagaskara)

---

Top Contributors

[![bhagaskara](https://avatars.githubusercontent.com/u/24548806?v=4)](https://github.com/bhagaskara "bhagaskara (3 commits)")

### Embed Badge

![Health badge](/badges/lara-pack-repository/health.svg)

```
[![Health](https://phpackages.com/badges/lara-pack-repository/health.svg)](https://phpackages.com/packages/lara-pack-repository)
```

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M190](/packages/laravel-telescope)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M529](/packages/laravel-passport)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M256](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M591](/packages/laravel-prompts)

PHPackages © 2026

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