Download the PHP package okipa/laravel-base-repository without Composer
On this page you can find all versions of the php package okipa/laravel-base-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download okipa/laravel-base-repository
More information about okipa/laravel-base-repository
Files in okipa/laravel-base-repository
Package laravel-base-repository
Short Description An abstract base repository with predefined common features.
License MIT
Homepage https://github.com/Okipa/laravel-base-repository
Informations about the package laravel-base-repository
laravel-base-repository
An abstract base repository with predefined common features.
Before starting
The repository pattern has several objectives :
- Encourage development good practices (separation of concerns, code reusability, ...)
- Improve code testability
Before using this package, you should be familiar with the repository pattern, and especially with its Laravel implementation.
You can know more about it by reading the several articles you'll can find on Internet about this.
Here is one among others : https://medium.com/@jsdecena/refactor-the-simple-tdd-in-laravel-a92dd48f2cdd.
Notes :
- This base repository does NOT allow you to manipulate the model : it can sometimes be tempting to directly manipulate the model from your controller but this is not recommended and recognized as a bad practice.
- You should always fill your repositories interfaces : it can avoid huge errors on your projects.
- The provided methods are shortcuts to avoid you to declare them in your own base repository or in several repositories. Keep in mind that they only are pre-defined methods and that you should declare new methods in your repositories if they does not fit with your needs.
Installation
The repository pattern setup is not complicated but requires several steps to be accomplished.
Follow them one by one :
-
Install the package with composer :
-
Create a
app/Repositories
directory where you will store your different project repositories. -
Create your
app/Repositories/BaseRepositoryInterface.php
interface and yourapp/Repositories/BaseRepository.php
abstract class : -
Create a first
UserRepositoryInterface
and its associatedUserRepository
: -
Create your project
app/Providers/RepositoryServiceProvider.php
file. You can follow the example below : -
Add your
RepositoryServiceProvider
to the providers declarations of the Laravel framework, in theconfig/app.php
: - Add a
$repository
attribute to yourapp/Http/Controllers/Controller.php
base controller that all your controllers will extends :
And you're done !
You can now use your UserRepository, empowered with the pre-defined methods provided by this package.
Usage
In your app/Http/Controllers/Users/UsersController.php
, manipulate your UserRepository
as in the example bellow :
API
Properties
See the protected properties that can be overridden in your own repositories in the BaseRepository.
Public methods
See the available public methods in the BaseRepositoryInterface.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributors
License
The MIT License (MIT). Please see License File for more information.