Skip to content

gkalmoukis/laravel-repositories

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Model Repository

A simple package to use Repository Pattern approach for Eloquent models.

Repository pattern

Repositories are classes or components that encapsulate the logic required to access data sources. They centralize common data access functionality, providing better maintainability and decoupling the infrastructure or technology used to access databases from the domain model layer. Microsoft

Installation

Require the package using composer:

composer require gkalmoukis/laravel-repositories

Command and Configuration

To use this package, you need to have repository class bound to laravel model class . This package includes a command that make it easy to to create repository classes from command line . to create a new repository class, run the following command

php artisan make:repository Repository --model=DummyModel

Usage

The best way to use the repository classes via Dependency Injection through the controller classes . for example :

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Repositories\Repository;

class DummyController extends Controller {

	/**
     * create a new controller instance
     *
     * @param  \App\Repositories\Repository $repository
     * @return void
     */
    public function __construct(
        protected Repository $repository
    ) {}
}

And in that way one can already get a fully qualified repository class . Also to manually initiated :

$repository = new \App\Repositories\Repository(new DummyModel);

About

A simple package to use Repository Pattern approach for Eloquent models.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages