Download the PHP package mrtolouei/laravel-repository without Composer
On this page you can find all versions of the php package mrtolouei/laravel-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mrtolouei/laravel-repository
More information about mrtolouei/laravel-repository
Files in mrtolouei/laravel-repository
Package laravel-repository
Short Description A clean and flexible base repository package for Laravel that simplifies data access, enforces the repository pattern, and keeps your code organized and testable.
License MIT
Informations about the package laravel-repository
Laravel Repository
A clean and flexible base repository package for Laravel that simplifies data access, enforces the Repository Pattern, and keeps your application code organized, testable, and maintainable.
This package provides a reusable BaseRepository implementation with common Eloquent operations and a powerful filtering system.
Table of Contents
- Features
- Requirements
- Installation
- Basic Usage
- Available Methods
- Filtering System
- Query Builder & Chainable Methods
- Persisting Queries
- CRUD Operations
- Advanced Usage
- Testing
- Contributing
- License
Features
- Clean BaseRepository implementation
- Built‑in query builder helpers
- Dynamic filtering system with multiple operators
- Support for nested and OR conditions
- Relation filtering using dot notation
- Fluent query chaining
- Works with Laravel 9+
- Fully testable and extendable
Requirements
- PHP >= 8.0
- Laravel / Illuminate components >= 9.0
Installation
No configuration or service provider registration is required.
Basic Usage
Create a repository for your model by extending the BaseRepository.
Example Model
Create Repository
Available Methods
The BaseRepository provides many commonly used data access methods.
Create
Find
Update
Delete
Restore (Soft Deletes)
Insert Multiple
Where
OR Where
Where In
Where Not In
Order
Limit
Pagination
Aggregate Functions
Existence Check
Filtering System
The package includes a powerful filtering trait that allows structured filtering from arrays (useful for APIs).
Only fields listed in $allowedFilters can be filtered.
Example
Supported Operators
| Keyword | SQL Equivalent |
|---|---|
| eq | = |
| neq | != |
| gt | > |
| gte | >= |
| lt | < |
| lte | <= |
| like | LIKE |
| in | IN (...) |
Using Filters
Example usage in a controller:
Example filter input (from query parameters or request body):
Explanation
email.like:Finds users with email containing “example.com”is_active:Equals trueorgroup: Matches users aged 30+ or belonging to roles with IDs 1, 2, 3
Query Builder & Chainable Methods
All major query methods remain chainable:
| Method | Description | Example |
|---|---|---|
| query() | Get Builder instance | $userRepo->query()->where('active', true); |
| where(...) | Add where clause (supports array and closure) | $repo->where(['status' => 'active']); |
| with([...]) | Eager load relations | $repo->with(['posts', 'roles']); |
| orderBy() | Add order clause | $repo->orderBy('created_at', 'desc'); |
| limit() | Limit results | $repo->limit(10)->all(); |
Persisting Queries
Preserve query state across multiple operations:
Without calling persistQuery(), queries auto‑reset after each operation.
CRUD Operations
Advanced Usage
Powerful nested filter combinations with chaining:
Testing
Run tests using PHPUnit:
Contributing
- Fork the repository
- Create a feature branch (
feature/awesome-feature) - Commit your changes (
git commit -m 'Add new feature') - Push to the branch (
git push origin feature/awesome-feature) - Open a Pull Request
License
This package is open-sourced software licensed under the MIT license.
All versions of laravel-repository with dependencies
illuminate/support Version >=9.0
illuminate/database Version >=9.0
illuminate/pagination Version >=9.0