PHPackages                             frontier/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. [Database &amp; ORM](/categories/database)
4. /
5. frontier/repository

ActiveLibrary[Database &amp; ORM](/categories/database)

frontier/repository
===================

Laravel Frontier Repositories Package

v1.0.0(2mo ago)067↓100%[1 PRs](https://github.com/0xKhdr/frontier-repository/pulls)MITPHPPHP &gt;=8.2

Since Mar 1Pushed 2mo ago1 watchersCompare

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

READMEChangelogDependencies (11)Versions (5)Used By (0)

Frontier Repository
===================

[](#frontier-repository)

 **Repository Pattern with Transparent Caching for Laravel**

 [Installation](#installation) • [Quick Start](#quick-start) • [Caching](#caching) • [API Reference](#api-reference) • [Commands](#commands)

 [![Latest Version](https://camo.githubusercontent.com/36e6c91f119558209e3385d92bae23afbadf6a07da2c578f66646608e2834ff0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66726f6e746965722f7265706f7369746f7279)](https://camo.githubusercontent.com/36e6c91f119558209e3385d92bae23afbadf6a07da2c578f66646608e2834ff0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66726f6e746965722f7265706f7369746f7279) [![PHP Version](https://camo.githubusercontent.com/d8cb12d4161bcf3d0abb89bdcd751b5c5812aff012d9323cd8cc56633e950041/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322b2d373737424234)](https://camo.githubusercontent.com/d8cb12d4161bcf3d0abb89bdcd751b5c5812aff012d9323cd8cc56633e950041/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322b2d373737424234) [![Laravel Version](https://camo.githubusercontent.com/90210155bac22241d8c3a81738835c4191716502b7c03d18c3b181eaf2b2b814/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31307c31317c31322d464632443230)](https://camo.githubusercontent.com/90210155bac22241d8c3a81738835c4191716502b7c03d18c3b181eaf2b2b814/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31307c31317c31322d464632443230)

---

Features
--------

[](#features)

- ✅ **Repository Pattern** — Clean abstraction for data access
- ✅ **Decorator Caching** — Choose between simple or cached repository implementations
- ✅ **Full CRUD** — Create, Read, Update, Delete with consistent API
- ✅ **Advanced Queries** — Filtering, sorting, pagination, scopes
- ✅ **Module Support** — Works with internachi/modular

---

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

[](#installation)

```
composer require frontier/repository
```

---

Quick Start
-----------

[](#quick-start)

### 1. Create Interface

[](#1-create-interface)

It is best practice to always code against interfaces.

```
php artisan frontier:repository-interface UserRepository
```

### 2. Generate Repository

[](#2-generate-repository)

Create a standard repository that implements the interface.

```
php artisan frontier:repository UserRepositoryEloquent
```

### 3. Generate Repository Cache (Optional)

[](#3-generate-repository-cache-optional)

Create a decorator repository that adds caching.

```
php artisan frontier:repository-cache UserRepositoryCache
```

### 4. Bind in ServiceProvider

[](#4-bind-in-serviceprovider)

Bind your interface to either the standard repository or the cached one.

```
// app/Providers/RepositoryServiceProvider.php

// Option A: Standard Repository (No Caching)
$this->app->bind(UserRepository::class, function ($app) {
    return new UserRepositoryEloquent(new User());
});

// Option B: Cached Repository (Repository + Caching Decorator)
$this->app->bind(UserRepository::class, function ($app) {
    return new UserRepositoryCache(
        new UserRepositoryEloquent(new User())
    );
});
```

---

Caching
-------

[](#caching)

Caching is implemented via the Decorator Pattern. The `BaseRepositoryCache` wraps your `BaseRepository` and handles caching logic transparently.

### Architecture

[](#architecture)

```
┌─────────────────────────────────────────┐
│         UserRepository         │
└───────────────────┬─────────────────────┘
                    │ bind to either:
    ┌───────────────┴───────────────┐
    ▼                               ▼
UserRepositoryEloquent              UserRepositoryCache
extends BaseRepository              extends RepositoryCache
(Direct DB Access)                  (Caching Decorator)

```

### Usage

[](#usage)

Inject the interface into your controllers or actions:

```
class UserController extends Controller
{
    public function __construct(
        protected UserRepository $users
    ) {}

    public function index()
    {
        // Automatically cached if UserRepositoryCache is bound
        return $this->users->retrieve();
    }
}
```

### Cache Control Methods

[](#cache-control-methods)

The `BaseRepositoryCache` exposes helper methods to control cache behavior:

```
// Skip cache for this query
$users->withoutCache()->retrieve();

// Force refresh cache
$users->refreshCache()->retrieve();

// Clear all cache
$users->clearCache();
```

---

Caching Behavior
----------------

[](#caching-behavior)

MethodBehavior`retrieve()`Cached (Read)`retrievePaginate()`Cached (Read)`find()`Cached (Read)`findOrFail()`Cached (Read)`count()`Cached (Read)`exists()`Cached (Read)`create()`Invalidates Cache`update()`Invalidates Cache`delete()`Invalidates Cache`updateOrCreate()`Invalidates Cache`insert()`Invalidates Cache`upsert()`Invalidates Cache---

Configuration
-------------

[](#configuration)

Publish config:

```
php artisan vendor:publish --tag=repository-config
```

```
// config/repository-cache.php
return [
    'enabled' => env('REPOSITORY_CACHE_ENABLED', true),
    'driver' => env('REPOSITORY_CACHE_DRIVER', null),
    'ttl' => env('REPOSITORY_CACHE_TTL', 3600),
];
```

---

Artisan Commands
----------------

[](#artisan-commands)

CommandDescription`frontier:repository {name}`Create standard repository`frontier:repository-cache {name}`Create cached repository decorator`frontier:repository-interface {name}`Create repository interface`frontier:repository-action {name}`Create repository actionAll commands support the `--module` flag for modular applications.

---

CRUD Operations
---------------

[](#crud-operations)

```
// CREATE
$user = $this->users->create(['name' => 'John']);

// READ
$user = $this->users->find(['id' => 1]);
$users = $this->users->retrieve();
$users = $this->users->retrievePaginate(['*'], ['per_page' => 15]);

// UPDATE
$count = $this->users->update(['id' => 1], ['name' => 'Jane']);

// DELETE
$count = $this->users->delete(['id' => 1]);
```

---

Advanced Queries
----------------

[](#advanced-queries)

The `retrieve()` and `retrievePaginate()` methods accept an `$options` array to build complex queries without writing boilerplate.

```
$users = $this->users->retrieve(['id', 'name', 'email'], [
    // Filtering (requires EloquentFilter on Model)
    'filters' => ['status' => 'active', 'role' => 'admin'],

    // Scopes
    'scopes' => ['verified', 'olderThan' => [18]],

    // Relationships
    'with' => ['profile', 'posts'],
    'with_count' => ['posts'],

    // Sorting
    'sort' => 'created_at',
    'direction' => 'desc',

    // Pagination (for retrievePaginate)
    'per_page' => 25,

    // Limits & Offsets
    'limit' => 10,
    'offset' => 5,

    // Grouping
    'group_by' => ['status'],
    'distinct' => true,
]);
```

### Supported Options

[](#supported-options)

OptionDescriptionExample`filters`Apply Eloquent filters`['status' => 'active']``scopes`Apply local scopes`['active', 'type' => ['admin']]``with`Eager load relations`['profile']``with_count`Count relations`['comments']``sort`Order by column`'created_at'``direction`Order direction`'desc'``per_page`Items per page`15``limit`Limit results`10``offset`Offset results`5``distinct`Distinct selection`true``joins`Join tables`['posts' => ['users.id', '=', 'posts.user_id']]`Note

To use `filters`, your Eloquent Model must use the `Filterable` trait (typically from `tucker-eric/eloquentfilter`).

---

Development
-----------

[](#development)

```
composer test          # Run tests
composer lint          # Fix code style
composer rector        # Apply refactorings
```

---

Related Packages
----------------

[](#related-packages)

PackageDescription[frontier/frontier](https://github.com/0xKhdr/frontier)Laravel Starter Kit[frontier/action](https://github.com/0xKhdr/frontier-action)Action Pattern[frontier/module](https://github.com/0xKhdr/frontier-module)Modular Architecture---

🤝 Contributing
--------------

[](#-contributing)

1. Follow PSR-12 coding standards
2. Use Laravel Pint for code styling
3. Write tests using Pest
4. Add strict types to all PHP files

---

📄 License
---------

[](#-license)

MIT License - see [LICENSE](LICENSE) for details.

---

👤 Author
--------

[](#-author)

**Mohamed Khedr** —

---

 Made with ❤️ for the Laravel community

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance87

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

Unknown

Total

1

Last Release

70d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f70f41f51a4ac47d17d99a5b2207cbab2e9fbffb185e3bac694ca76a55b7074d?d=identicon)[MohamedKhedr700](/maintainers/MohamedKhedr700)

---

Top Contributors

[![0xkhdr](https://avatars.githubusercontent.com/u/79449923?v=4)](https://github.com/0xkhdr "0xkhdr (64 commits)")

---

Tags

laravelrepositoryfrontierdata access

###  Code Quality

TestsPest

Static AnalysisRector

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8425.3M87](/packages/laravel-doctrine-orm)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)

PHPackages © 2026

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