nda666/laravel-repository-pattern

Simple repository pattern for laravel project

1.1.0 2022-07-29 04:18 UTC

This package is auto-updated.

Last update: 2024-05-06 23:50:39 UTC


README

It's a simple repository file generator.

Laravel without auto-discovery:

If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php

LaravelRepositoryPattern\Providers\RepositoryPatternProvider::class

to publish the config file:

php artisan vendor:publish --provider="LaravelRepositoryPattern\Providers\RepositoryPatternProvider"

How To:

php artisan make:repository User

Will generate UserRepository.php and UserInterface.php file

Example

Example using generated repo in controller

<?php

namespace App\Http\Controllers;

use App\Repositories\UserRepository;

class HomeController extends Controller
{
    protected UserRepository $user;

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

    public function index()
    {
        return $this->user->getAll();
    }
}