aleprosli/repository-pattern

v0.1.2 2023-02-23 14:35 UTC

This package is auto-updated.

Last update: 2025-03-28 19:30:47 UTC


README

Automatic generate repo pattern with single command

Installation

composer require aleprosli/repository-pattern

Configuration

Publish the configuration file

php artisan vendor:publish --provider="Aleprosli\RepositoryPattern\RepositoryServiceProvider"

Go To

config.php and import register Repository Service Provider

'providers' => [
        Aleprosli\RepositoryPattern\RepositoryServiceProvider::class
    ],

Usage

The command

php artisan make:repo Model

Example

php artisan make:repo User

Go To

Providers/RepositoryServiceProvider.php and bind interface and class you just created

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class RepositoryServiceProvider extends ServiceProvider
{

    public function register()
    {
        $this->app->bind('App\Repositories\UserRepositoryInterface','App\Repositories\UserRepository');
    }
}

And now go to

app/Http/Controllers/Usercontroller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Repositories\UserRepositoryInterface;

class UserController extends Controller
{
    private $user;

    public function __construct(UserRepositoryInterface $user)
    {
        $this->user = $user;
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $users = $this->user->all();
        
        dd($users);
    }
}

THEN YOU GOOD TO GO. FEELS FREE TO CONTRIBUTE :)