Skip to content

this package helps to implement better repository pattern on your laravel projects

Notifications You must be signed in to change notification settings

matin-kh73/RepositoryPattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Total Downloads Latest Stable Version License

About RepositoryPattern

The Repository Pattern is one of the most popular patterns to create an enterprise level application. It restricts us to work directly with the data in the application and creates new layers for database operations, business logic, and the application’s UI. using the Repository Pattern has many advantages:

  • Your business logic can be unit tested without data access logic;
  • The database access code can be reused;
  • Your database access code is centrally managed so easy to implement any database access policies, like caching;
  • It’s easy to implement domain logic;
  • Your domain entities or business entities are strongly typed with annotations; and more.

How to work with this package

php artisan make:repository ModelName

After installing this package, a command will be added on your artisan command with make:repository name. with this command you can create a repository class for your model classes.

After running this command if the model exists, a directory called Repository creates in your app directory.to use your repository class you can inject it in any controller that you want. after that you can easily use all of the features in your repository class.

etc

php artisan make:repository Models\User

In this example, you can see a method with setFilters name!

you can apply your any eloquent filters on your query.but where is these filters??

You can create your filters with this command:

php artisan make:filter With'

After creating the filter, the structure of this class like this :

The implementation of your filter must be in the handle method! the args variable includes the value that you set on the setFilters method!

Be careful after creating the filters, you have to set filters on the repository config file.

In the repositories directory, there are 4 things!

  • a BaseRepository class that is the parent of all repositories that you created in your project and includes and contains a number of functions that can be the same in your repository classes.
  • a BaseRepositoryInterface class
  • a RepositoryServiceProvider for binding your repository classes to the interface that previously made.
  • and finally, a directory with your model name that includes a repository class is created and a directory with contracts name.

Be careful If you want using your repository class with their contracts you have to bind them together on the RepositoryServiceProvider class!

License

The RepositoryPattern-handler is open-sourced software licensed under the MIT license.

About

this package helps to implement better repository pattern on your laravel projects

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages