Download the PHP package robertgdev/laravel-base-repository without Composer
On this page you can find all versions of the php package robertgdev/laravel-base-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download robertgdev/laravel-base-repository
More information about robertgdev/laravel-base-repository
Files in robertgdev/laravel-base-repository
Package laravel-base-repository
Short Description A lightweight base repository for Laravel Eloquent models with full CRUD and query support, no Criteria overhead.
License MIT
Informations about the package laravel-base-repository
Base Repository for Laravel
A lightweight base repository for Laravel Eloquent models with full CRUD and query support. No Criteria pattern, no magic — just a clean wrapper around Eloquent that makes your data access layer consistent, testable, and free of boilerplate.
Installation
Quick Start
1. Create a repository
2. Inject and use
Laravel's container auto-resolves your repository. Just type-hint it:
Available Methods
All methods mirror Eloquent conventions and work identically to their Eloquent counterparts:
Retrieval
| Method | Description |
|---|---|
find($id) |
Find by primary key, returns model or null |
findOrFail($id) |
Find by primary key, throws ModelNotFoundException |
findOr($id, $callback) |
Find by id or invoke callback |
findOrNew($id) |
Find by id or return new unsaved instance |
findMany($ids) |
Find multiple models by id array |
first($columns) |
First record or null |
firstOrFail($columns) |
First record or throws |
firstOr($columns, $callback) |
First record or invoke callback |
firstOrCreate($attributes, $values) |
Find first match or create |
firstOrNew($attributes, $values) |
Find first match or new instance |
all($columns) |
All records as a Collection |
get($columns) |
Fresh query result as a Collection |
paginate($perPage, ...) |
Paginated results |
chunk($count, $callback) |
Process records in chunks |
lazy($chunkSize) |
Lazy collection for memory-efficient iteration |
count($where) |
Count records, optionally filtered |
exists($where) |
Check if matching records exist |
doesntExist($where) |
Check if no matching records exist |
query() |
Raw Eloquent Builder for custom queries |
Mutation
| Method | Description |
|---|---|
create($attributes) |
Create and persist a model |
make($attributes) |
New unsaved instance |
update($id, $attributes) |
Update by id, returns updated model or null |
updateOrCreate($attributes, $values) |
Update existing or create |
delete($id) |
Delete by id (respects SoftDeletes) |
forceDelete($id) |
Hard delete regardless of SoftDeletes |
restore($id) |
Restore a soft-deleted record |
Adding Custom Queries
Use the query() escape hatch to compose any Eloquent query directly:
Testing
Mock the repository in your tests — no database needed:
Or use the repository itself in integration tests. The package ships with its own test suite (Pest, SQLite in-memory) that exercises every method.
Package Tests
Requirements
- PHP 8.3+
- Laravel 11.x / 12.x / 13.x
License
MIT. See LICENSE.
All versions of laravel-base-repository with dependencies
illuminate/database Version >=13.0
illuminate/pagination Version >=13.0
illuminate/support Version >=13.0