Download the PHP package cariuk/laravel-repository-pattern without Composer
On this page you can find all versions of the php package cariuk/laravel-repository-pattern. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cariuk/laravel-repository-pattern
More information about cariuk/laravel-repository-pattern
Files in cariuk/laravel-repository-pattern
Package laravel-repository-pattern
Short Description A flexible and powerful Laravel package implementing the Repository Pattern with SOLID principles, featuring auto-detection, dependency injection, CRUD operations, filtering, sorting, pagination, and soft deletes support.
License MIT
Homepage https://github.com/cariuk/repository-pattern-laravel
Informations about the package laravel-repository-pattern
Laravel Repository Pattern
A flexible and powerful Laravel package that implements the Repository Pattern with built-in support for CRUD operations, filtering, sorting, pagination, eager loading, and soft deletes.
Features
- Clean Architecture: Separation of concerns with trait-based composition
- Automatic CRUD: Pre-built create, read, update, and delete operations
- Smart Filtering: Request-driven filtering with custom filter hooks
- Sorting & Pagination: Built-in support for sorting and pagination
- Eager Loading: Control relationship loading via request parameters
- Soft Delete Support: Full support for Laravel's soft deletes with trash management
- Lifecycle Hooks: Extensible hooks for custom logic (onCreated, onUpdated, onDeleted, etc.)
- Transaction Safety: Automatic database transaction wrapping for write operations
- Artisan Command: Generate repositories quickly with
make:repositorycommand
Requirements
- PHP 8.1 or higher
- Laravel 12.0 or higher
Installation
Install the package via Composer:
The service provider will be automatically registered.
Quick Start
1. Generate a Repository
Use the Artisan command to generate a repository for your model:
This will create app/Repositories/UserRepository.php:
If your model uses SoftDeletes, the command will automatically extend RepositorySoftDelete instead.
2. Configure the Repository
3. Use in Controllers
API Reference
Available Methods
Reading Operations
Creation & Update Operations
Deletion Operations
Soft Delete Operations (only for RepositorySoftDelete)
Request Parameters
Control repository behavior via URL query parameters:
Advanced Usage
Lifecycle Hooks
Override these methods to add custom logic at different stages:
Custom Data Processing
Using Query Modifiers
Query modifiers allow you to add custom conditions to queries:
Working with Relationships
Disable Pagination
Configuration Options
| Property | Type | Default | Description |
|---|---|---|---|
$fillable |
array |
[] |
Allowed fields for mass assignment |
$paginationable |
bool |
true |
Enable/disable pagination |
$optionalPagination |
bool |
false |
Allow pagination to be disabled via request |
$paginatePerPage |
int |
10 |
Default number of items per page |
$sortable |
bool |
true |
Enable/disable sorting |
$sortAllowedFields |
array |
['id'] |
Fields allowed for sorting |
$defaultSortField |
string\|null |
null |
Default field to sort by |
$defaultSortDescending |
bool |
false |
Default sort direction |
$relationable |
bool |
false |
Enable/disable eager loading |
$relationAllowed |
array |
[] |
Relationships allowed to be loaded |
Best Practices
1. Keep Repositories Focused
Each repository should handle one model:
2. Use Form Requests for Validation
3. Implement Service Layer for Complex Logic
4. Use Type Hints
5. Cache Frequently Accessed Data
Testing
Troubleshooting
Transaction Deadlocks
If you experience transaction deadlocks with nested repositories:
Memory Issues with Large Datasets
For large datasets, disable pagination carefully:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This package is open-sourced software licensed under the MIT license.
Credits
Developed and maintained by Cariuk
Support
If you discover any security vulnerabilities, please email us instead of using the issue tracker.
For general questions and issues, please use the GitHub issue tracker.