Download the PHP package irfan-chowdhury/repository-maker without Composer
On this page you can find all versions of the php package irfan-chowdhury/repository-maker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download irfan-chowdhury/repository-maker
More information about irfan-chowdhury/repository-maker
Files in irfan-chowdhury/repository-maker
Package repository-maker
Short Description This package will generate the necessary files for the repository design pattern environment.
License MIT
Homepage https://github.com/Irfan-Chowdhury/repository-maker
Informations about the package repository-maker
About Repository Design Pattern:
The Repository Design Pattern is a software design principle commonly used in the development of applications that interact with data storage systems, such as databases. It provides an abstraction layer between the application's data access logic and the underlying data storage, promoting separation of concerns and modularity in the codebase.
In short, the Repository Design Pattern involves creating classes or interfaces called repositories, which encapsulate the methods and operations for interacting with the data storage. These repositories abstract away the details of how data is retrieved, stored, and manipulated, making the application's codebase more maintainable and testable. This pattern also helps in centralizing data access logic, improving code reusability, and facilitating the management of complex queries.
Requirement:
Installation
You can install the package via composer:
Setup
After installation goto config/app.php
and paste the bellow line in "providers" array
Usage
If you now run php artisan
you will see some new commands in the list:
make:contract
make:contract-base
make:contract-extends
make:repository
make:repository-i
make:repository-base
make:repository-extends
make:service
make:repository-i-s
Commands
Note:
- Before using repository you have to ensure that your model class exists or not.
- You have to register the dependency in
register()
method inAppServiceProvider
. If you want you can create a custom service provider. Following the bellow code -
Example
Let you have a User Model according to this namespace App\Models\User.php
Creating Interface
it will generate an interface according to this path app/Contracts/UserContract.php
. Here we named this interface as Contract.
Creating a Base Interface
It is optional but if you want to use a base, it will generate an interface according to this path app/Contracts/BaseContract.php
. Here we named this interface as Contract.
Creating an Interface with extends Base Interface
If you want to extends with the Base Interface, it will generate an interface according to this path app/Contracts/UserContract.php
and extends with BaseContract
.
Note: But before using extends with the Base interface, you have to create a BaseContract before (using only make:contract-base
).
Creating Repository
It will generate a repository class according to this path app/Repositories/UserRepository.php
.
Creating Repository with interface
It will generate a repository class with interface according to this path app/Repositories/UserRepository.php
and app/Contracts/UserContract.php
.
Creating a Base Repository
It is optional but if you want to use a base, it will generate a repository class according to this path app/Repositories/BaseRepository.php
.
Creating a Repository with extends the Base Repository
If you want to extends with Base Repository, it will generate a Repository class according to this path app/Repositories/UserRepository.php
and extends with BaseRepository
.
Note: But before using extends with the Base repository, you have to create a BaseRepository class before (using only make:repository-base
).
Creating Service Class
It is optional but sometimes we need to use a service class to maintain business logic. If you want to use a service class, it will generate a service class according to this path app/Services/UserService.php
.
Creating Repository with interface and service
It will generate a repository class with interface and service according to this path app/Repositories/UserRepository.php
, app/Contracts/UserContract.php
, app/Services/UserService.php
.
After then you have to register in a service provider -
Inject in Controller/Service class
In your controlleror, you can use them,
Visit
Packagist : https://packagist.org/packages/irfan-chowdhury/repository-maker
Credits
- Inspired by Abdullah Al Zuhair
- Resources - Bitfumes and Maniruzzaman Akash
- Structure follow from - spatie/package-skeleton-laravel