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(10mo ago)025MITPHP

Since Aug 19Pushed 4mo 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 3w 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

30

—

LowBetter than 62% of packages

Maintenance67

Regular maintenance activity

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

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

309d ago

### Community

Maintainers

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

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k104.3M829](/packages/laravel-socialite)[laravel/dusk

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

1.9k38.6M289](/packages/laravel-dusk)[pinguo/php-msf

Pinguo Micro Service Framework For PHP

1.7k4.2k](/packages/pinguo-php-msf)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)[link-cloud/fast-hyperf

LinkCloud Fast Hyperf

241.2k1](/packages/link-cloud-fast-hyperf)

PHPackages © 2026

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