Download the PHP package amondar-libs/repository-pattern without Composer

On this page you can find all versions of the php package amondar-libs/repository-pattern. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package repository-pattern

amondar-libs/repository-pattern

Laravel package to implement a clean Repository + Service pattern with a tiny, expressive API.

Requirements

Installation

No service provider registration is required.

Simple usage

This section shows the typical way to use the package: define a Model, optionally a Data object, and a Repository bound to that Model via an attribute.

1) Your Eloquent model

2) (Optional) A Data object

If you prefer typed DTOs, use spatie/laravel-data. The repository accepts arrays or Data instances and normalizes them automatically.

3) Your Repository bound to the model via attribute

4) Use the repository

Notes:

Dive deep: quietly and transaction

Two higher‑order helpers are available to control side effects.

You can use them independently or together.

Run quietly (suppress Eloquent events)

Under the hood, quietly uses Model::withoutEvents(...) around your repository call.

Run in a database transaction

Combine: transaction + quietly

Sometimes you want both: atomic writes and no model events.

Tip: Laravel’s ShouldDispatchAfterCommit events will be dispatched only after a successful commit when used inside a transaction. If the transaction rolls back, those events won’t be dispatched.

Run transaction with pessimistic locking (avoid lost updates)

Sometimes you want to make an atomic update with pessimistic lock.

Tip: You can add ->withTrashed->forUpdate(...) after transaction to get a soft-deleted model viable for update.

Optimistic locking (avoid lost updates)

Besides pessimistic locks, the package also supports optimistic locking to prevent lost updates without holding row locks.

How it works:

Migrations:

Model setup:

Raw model usage:

Usage through a repository:

Tips:

It's highly recommended to use cache for attributes in production. To do so, implement Amondar\RepositoryPattern\Contracts\WithAttributesCache. Use any available cache driver from spatie/php-structure-discoverer, because it is a part of the php-attributes package used in a particular version.

In Laravel projects - use new \Spatie\StructureDiscoverer\Cache\LaravelDiscoverCacheDriver('YOUR_CACHE_PREFIX') - to use default cache driver of your Laravel application.

Service layer (optional)

You can build services on top of repositories. The Service base class provides a transaction helper as well. Example with handy create/update traits. Also, you can use traits to add target methods into commands in the CQRS pattern.

Service transactions

The service also exposes a transaction helper:

If the method throws, the transaction is rolled back and any ShouldDispatchAfterCommit events are not dispatched.

Data normalization

Repository::create() and Repository::update() accept either:

This lets you keep controllers/services strongly typed while repositories remain simple.

Exceptions

Types and generics (PHPDoc)

The classes are annotated with generics to improve static analysis in IDEs:

License

MIT. See LICENSE.md.


All versions of repository-pattern with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
spatie/laravel-package-tools Version ^1.16
spatie/laravel-data Version ^4.18
amondar-libs/class-attributes Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package amondar-libs/repository-pattern contains the following files

Loading the files please wait ...