Download the PHP package puncoz/laravel-repository without Composer
On this page you can find all versions of the php package puncoz/laravel-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download puncoz/laravel-repository
More information about puncoz/laravel-repository
Files in puncoz/laravel-repository
Package laravel-repository
Short Description A basic light weight package to implement Repository Design Pattern in Laravel.
License MIT
Homepage https://github.com/JoBinsJP/laravel-repository
Informations about the package laravel-repository
Laravel Repository Pattern Implementation
A lightweight and flexible implementation of the Repository Pattern for Laravel applications. This package provides a clean and consistent way to handle data access layers in your Laravel applications.
Features
- Clean and simple Repository Pattern implementation
- Built-in filtering system with criteria pattern
- Data transformation using Fractal
- Scope query support
- Soft delete handling
- Eloquent model integration
- Flexible and extensible architecture
Installation
You can install the package via composer:
You can publish the config file with:
Basic Usage
-
Create a repository interface:
-
Create a repository implementation:
- Register the repositories in the service provider:
In Laravel 11 and 12, manually register your service provider in bootstrap/providers.php:
- Use the repository in your application:
✅ Ready to rock!
Now, Laravel will automatically resolve the correct repository implementation via the interface wherever it's type-hinted using constructor injection or service container resolution.
⚙️ New Artisan Commands
This package now includes three powerful Artisan commands to help scaffold Repositories, Transformers, and Filters with minimal effort.
🔧 Configuration You can customize the default paths via the repository file located at: config/repository.php
📦 make:repository
-
interface_subfolder:
-
If true, the interface will be placed in an Interfaces/ subfolder.
- If false, it will be placed in the same folder as the repository.
Generate Repository and Interface as same time with:
Example
This will generate:
-
app/Repositories/Product/StockRepository.php
-
app/Repositories/Product/Interfaces/StockRepositoryInterface.php (if interface_subfolder is true)
- Or app/Repositories/Product/StockRepositoryInterface.php (if false)
It automatically handles:
-
Folder creation
-
Proper naming conventions
- Namespace and use statements
🔄 make:transformer
Generate a Transformer class.
Example
✅ This will generate:
- app/Transformers/Product/StockTransformer.php
🔍 make:filter
Generate a Filter class for Eloquent query filtering.
Example
✅ This will generate:
- app/Filters/Product/StockFilter.php
🧠 💡 Notes
-
Slashes (/) in names are used to create subdirectories automatically.
-
All files are created with proper namespaces and boilerplate code to get you started instantly.
- You can override default paths using the config file or environment variables.
Available Methods
Basic Operations
all(array $columns = ['*']): Get all recordsfind(int|string $modelId, array $columns = ['*']): Find by IDfindByField(string $field, mixed $value, array $columns = ['*']): Find by fieldgetByField(string $field, mixed $value, array $columns = ['*']): Get multiple (list/collection) by fieldcreate(array $data): Create new recordupdate(array $data, int|string $modelId): Update recorddelete(int|string $modelId): Delete recorddeleteWhere(array $where): Delete by conditionsupdateOrCreate(array $queries, array $values = []): Update or create record
Filtering and Scopes
filter(FilterCriteria $filter): Apply filter criteriaskipFilters(bool $status = true): Skip filtersresetFilters(): Reset all filtersscopeQuery(Closure $scopeQuery): Add query scope
Data Transformation
setTransformer(TransformerAbstract|string $transformer): Set transformerskipTransformer(bool $skip = true): Skip transformationpresent(Collection|AbstractPaginator|Model $data): Present data using transformer
Relations
with(string|array $relations): Eager load relationssetIncludes(array|string $includes): Set transformer includes
Creating Custom Filters
-
Create a filter class:
- Apply the filter with queries:
How Filters Work
-
Query Parameter to Method Mapping:
- queries/filters array is passed to the constructor
- Query/filter parameters (keys in the array passed to the constructor) are automatically mapped to filter methods
- Method names must be in camelCase and end with 'Filter' suffix
- Examples:
search=>searchFilter()user_status=>userStatusFilter()created_at=>createdAtFilter()
-
Filter Method Signature:
- First parameter: Eloquent Query builder instance
- Second parameter: Value from the queries array
- Must return: Eloquent Query Builder instance
-
Filter Lifecycle:
preHook: Runs before any filter methods- Filter methods: Run in the order they are defined
postHook: Runs after all filter methods
- Optional Methods:
- All filter methods are optional
preHookandpostHookare optional- Only methods matching query parameters will be called
Data Transformation
The package uses Fractal Transformers for data transformation. Here's how to implement transformers:
-
Create a transformer class:
- Use transformation in your application:
Testing
The test suite uses Pest on top of Orchestra Testbench with an in-memory SQLite database, so no external services are needed.
tests/Unitcovers standalone classes such as the serializer and the Fractal param bag.tests/Featureboots the package inside Testbench and covers the service provider, themake:repository,make:transformerandmake:filtercommands, and theLaravelRepositorybase class.- Generator command tests write into a temporary base path that is removed after each test.
Static analysis settings live in phpstan.neon.dist. CI runs Pest and PHPStan for every supported PHP and Laravel combination (see .github/workflows/run-tests.yml).
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Puncoz Nepal
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-repository with dependencies
illuminate/database Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^9.0|^10.0|^11.0|^12.0|^13.0
league/fractal Version ^0.20.1