ahmedmahmoud / repository-pattern
A Laravel package to implement the Repository Pattern
Installs: 10
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/ahmedmahmoud/repository-pattern
Requires
- php: ^8.1
- illuminate/support: ^10.0|^11.0|^12.0
- laravel/framework: ^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.0
README
This 'Package' support only api A powerful package to automatically generate the complete repository pattern structure for your Laravel applications.
Features
- 🚀 Auto-generates all repository pattern components with one command
- 📦 Includes: Model, Repository, Service, Controller, Form Requests, Migration
- 🔄 Supports both API
- âš¡ Easily extendable base classes
- 🔧 Customizable stubs
Installation
- Require the package via Composer:
composer require ahmedmahmoud/repository-pattern
2.(Optional) Publish stubs for customization:
php artisan vendor:publish --tag=repository-stubs --force
- Run the setup command to install base files:
php artisan repository:setup
- Generate complete structure for a new model:
php artisan make:repo {name : The name of the repository} --all (Includes: Model, Repository, Service, Controller, Form Requests, Migration}
🧩 Dependency Injection Binding
The package automatically registers repository bindings in the service container:
$this->app->when(ProductService::class) ->needs(RepositoryInterface::class) ->give(ProductRepository::class);
if you not install api this return in your terminal
out when installed api then try this command again
php artisan make:repo student --all Created migration file for students table. Cannot write to C:\xampp_new\htdocs\first_package\routes/api.php. Please manually add the following to routes/api.php: use Illuminate\Support\Facades\Route; use App\Http\Controllers\StudentController; Route::resource('students', StudentController::class); Repository pattern files for Student created successfully!
How it works:
- when(): Specifies the service class that needs dependency
- needs(): Defines the interface/abstract type needed
- give(): Provides the concrete implementation
You can find these bindings in:
app/Providers/RepositoriesServiceProvider.php
And File
bootstrap/providers/RepositoriesServiceProvider.php