Download the PHP package gohari/repository-pattern without Composer
On this page you can find all versions of the php package gohari/repository-pattern. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gohari/repository-pattern
More information about gohari/repository-pattern
Files in gohari/repository-pattern
Package repository-pattern
Short Description A Laravel package to generate and use clean repository pattern classes with Artisan commands.
License MIT
Informations about the package repository-pattern
Gohari Laravel Repository Pattern
Build clean repositories for Laravel models with one Artisan command.
gohari/repository-pattern provides a reusable BaseRepository, a matching BaseRepositoryInterface, and a generator command that creates repository classes inside the Laravel application that installs your package.
Current release: v2.0.0
Documentation: mohammadrezagohari.github.io/RepositoryPattern
Features
- Artisan repository and service layer generator
- Automatic Laravel package discovery
- Automatic model creation for missing
App\Models\...classes - Repository and interface stubs
- Custom output path support
- Optional automatic interface binding
- Optional Service, ServiceInterface, model-aware DTO, and config generation
- Relationship loading, sorting, and soft delete helpers
- Shared base methods for common Eloquent operations
- Backward-compatible method aliases like
insertData,updateItem, anddeleteData - PHPUnit and Orchestra Testbench coverage for package behavior
Requirements
- PHP
^8.3 - Laravel
^10.0,^11.0,^12.0, or^13.0
Installation
Install the package with Composer:
Laravel will discover the service provider automatically:
If package discovery is disabled in your app, register the provider manually in config/app.php:
Publish the config or generator stubs when you want to customize package defaults:
Published stubs live in:
Quick Start
Create a repository for a model:
This creates:
If App\Models\User does not exist, the package will create it with Laravel's make:model command.
Command Usage
Arguments and options:
| Name | Required | Description |
|---|---|---|
name |
Yes | Repository name. User and UserRepository both generate UserRepository. |
--model |
No | Model class name or FQCN. Defaults to the repository name. |
--path |
No | Output directory. Defaults to app/Repositories. |
--interface-path |
No | Repository interface output directory. Defaults to app/Repositories/Contracts. |
--force |
No | Overwrite existing repository files. |
--bind |
No | Bind the generated interface to the repository in App\Providers\RepositoryServiceProvider. |
--service |
No | Generate Service, ServiceInterface, DTO, and config alongside the repository. |
--service-path |
No | Service output directory. Defaults to app/Services. |
--dto |
No | Generate only the DTO alongside the repository. |
--dto-path |
No | DTO output directory. Defaults to app/DTOs. |
--config |
No | Copy config/repository-pattern.php into the application. |
Examples:
Use a custom output path:
Overwrite existing files:
Create files and register the interface binding:
Generate repository and service layers together:
For fully-qualified model classes outside App\Models, the command will warn you if the model file is missing, but it will not generate it automatically.
Generated Repository
For this command:
The package generates:
And:
Base Repository Methods
Every generated repository extends BaseRepository, so these methods are available immediately:
Backward-compatible aliases:
Generated Service Layer
Use --service to generate Repository, RepositoryInterface, Service, ServiceInterface, DTO, and config in one command:
This creates:
The generated service only forwards pagination and lookup arguments to the repository. Query construction, relationships, sorting, and database access stay in the repository:
Pagination for Million-Row Tables
bigDataPaginate uses Laravel cursor pagination instead of offset pagination. It is intended for large tables and next/previous or infinite-scroll interfaces:
The JSON response contains next_cursor and prev_cursor; pass one of them as the next request's cursor. Cursor pagination does not provide page numbers or a total row count. For best performance, use an indexed, non-null sort column. The repository automatically adds the model primary key as a stable tie-breaker when needed. If you pass a custom $columns selection directly to the repository, include every sorted column and the primary key.
Use chunkById or lazyById for background jobs that must process an entire table; they are not replacements for API/UI pagination.
Model-Aware DTO Generation
When the model defines $fillable, the generator creates matching public readonly DTO fields. Primitive model casts are used for safe PHP types:
The generated UserData exposes name, age, is_active, and settings, and its toArray() method only returns provided fillable fields. Unknown input is discarded while explicitly provided null values are preserved. Fields without a safe primitive cast use mixed. If the model has no $fillable fields, the original generic array DTO is generated unchanged.
Binding Interfaces
You can bind repositories automatically with --bind:
This creates or updates app/Providers/RepositoryServiceProvider.php:
The command also registers App\Providers\RepositoryServiceProvider::class in bootstrap/providers.php for modern Laravel apps, or in config/app.php when that is the available provider registration file.
Configuration
After publishing repository-pattern-config, you can control paths, namespaces, and default generator behavior:
Then inject the interface anywhere:
Custom Repository Methods
Add domain-specific methods to the interface:
Then implement them in the repository:
Testing
Install development dependencies and run the package test suite:
The tests cover:
- Repository generator command
- Package service provider command registration
- Generated repository and interface contents
- Missing model generation for
App\Models --forceoverwrite behavior--bind,--service, DTO, config, and custom stub generation- Shared
BaseRepositoryCRUD/query behavior - Search, relationship loading, sorting, soft delete, and fluent repository scopes
- Legacy aliases:
insertData,updateItem,deleteData
Package Development
For packages, vendor/ and composer.lock should stay out of the repository. Install dependencies locally when developing:
Before tagging a release, run:
For Packagist, push your repository to GitHub, submit the package, and tag releases with semantic versions:
Security
Please review SECURITY.md before reporting vulnerabilities.
License
The MIT License. See LICENSE for more information.
All versions of repository-pattern with dependencies
illuminate/console Version ^10.0|^11.0|^12.0|^13.0
illuminate/database Version ^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^10.0|^11.0|^12.0|^13.0