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

5.0.0 2025-05-23 23:17 UTC

This package is auto-updated.

Last update: 2025-12-24 02:04:20 UTC


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

  1. Require the package via Composer:
composer require ahmedmahmoud/repository-pattern

2.(Optional) Publish stubs for customization:

php artisan vendor:publish --tag=repository-stubs --force
  1. Run the setup command to install base files:
php artisan repository:setup
  1. 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:

  1. when(): Specifies the service class that needs dependency
  2. needs(): Defines the interface/abstract type needed
  3. give(): Provides the concrete implementation

You can find these bindings in: app/Providers/RepositoriesServiceProvider.php

And File bootstrap/providers/RepositoriesServiceProvider.php