Download the PHP package darwinnatha/laravel-repository-pattern without Composer

On this page you can find all versions of the php package darwinnatha/laravel-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 laravel-repository-pattern

Laravel Repository Architecture Package

Latest Version on Packagist Total Downloads

A modern, robust, and type-safe Repository Pattern implementation for Laravel applications. Designed for API-first architecture, this package decouples your data layer, standardizes URL filtering/eager-loading, and enforces clean separation of concerns.


Key Features


Installation

Install the package via Composer:


Quick Start & CLI Usage

Generate a contract interface and its Eloquent implementation in one command:

Generates:


1. Custom Methods (Contract vs Implementation)

To ensure strict typing and allow your controllers to call specific methods directly via dependency injection, any custom method added to the Eloquent Repository must first be defined in its Interface (Contract).

Step 1: Define the Method in the Contract (CustomerRepository.php)

Step 2: Implement the Method in Eloquent (CustomerRepositoryEloquent.php)

Alternative with pagination:

Step 3: Direct Call from Controller

The interface CustomerRepository provides direct access to autocompletion for standard and custom methods:


Declarative API Querying (Pagination, Filters, Includes, Sorts & Relations)

Instead of manually building query builders, configure allowed API query parameters directly within the repository's constructor:


HTTP Query Parameter Usage

Once configured in your repository, frontend clients and API consumers can dynamically filter, include relationships, and sort data straight from the URL parameters:

1. Pagination (?paginate & ?page)

Pagination is automatically handled by the all() and trashed() methods of the repository when the paginate parameter is passed.

API clients can control the page size and navigate between pages via native Laravel URL query parameters:

2. Filtering (?filter[...])

Filter resources using exact matches, partial string searches, or model scopes:

3. Including Relationships (?include=...)

Dynamically eager-load allowed relationships specified in the 'includes' array:

4. Sorting (?sort=...)

Sort results dynamically using attributes defined in the 'sorts' array (prefix with - for descending order):

5. Combining Query Parameters

Combine pagination, filtering, eager-loading, and sorting in a single request:


Architectural Guidelines & Best Practices

1. Auto Eager-Loaded Relations (relations)

The 'relations' array automatically appends relations to every query executed by the repository (via $query->with(...)). Use this for core data that the model always depends on (e.g., profile or credential).

2. Controller vs. Service Layer Separation (CQRS / Actions)


Complete API Reference

Method Parameters Return Type Description
all() array $queries = [] Collection\|Paginator Retrieves all models. Supports ['paginate' => 15].
trashed() array $queries = [] Collection\|Paginator Retrieves all soft-deleted models. Supports ['paginate' => 15].
retrieve() string\|int $id, bool $withTrashed = false ?Model Finds a single model by primary key.
collect() array $ids, bool $withTrashed = false Collection Retrieves models matching an array of IDs.
where() array $conditions Collection Retrieves models matching a condition array.
whereFirst() array $conditions ?Model Retrieves first matching model or null.
whereFirstOrFail() array $conditions Model Retrieves first matching model or throws 404.
create() array $attributes, bool $withoutEvents = false ?Model Creates a model instance.
update() string\|int\|Model $id, array $attributes, bool $withoutEvents = false Model Updates an existing model.
createOrUpdate() array $conditions, array $attributes, bool $withoutEvents = false Model Executes an updateOrCreate operation.
delete() string\|int\|Model $id, bool $withoutEvents = false bool Deletes a model by ID or instance.
restore() string\|int\|Model $id, bool $withoutEvents = false bool Restores a soft-deleted model.
forceDelete() string\|int\|Model $id, bool $withoutEvents = false bool Permanently deletes a model.

Testing & Quality Assurance


License

The MIT License (MIT). Please see LICENSE.md for more information.


All versions of laravel-repository-pattern with dependencies

PHP Build Version
Package Version
Requires aaronfrancis/fast-paginate Version ^2.0
illuminate/contracts Version ^11.0|^12.0|^13.0
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0
spatie/laravel-package-tools Version ^1.16
spatie/laravel-query-builder Version ^6.0
symfony/finder Version ^6.0|^7.0|^8.0
php Version ^8.2
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 darwinnatha/laravel-repository-pattern contains the following files

Loading the files please wait ...