Download the PHP package wimski/laravel-model-repositories without Composer
On this page you can find all versions of the php package wimski/laravel-model-repositories. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wimski/laravel-model-repositories
More information about wimski/laravel-model-repositories
Files in wimski/laravel-model-repositories
Package laravel-model-repositories
Short Description Laravel model repositories
License MIT
Homepage https://github.com/wimski/laravel-model-repositories
Informations about the package laravel-model-repositories
Laravel Model Repositories
Generic repository pattern for Laravel Eloquent models.
- Changelog
- Usage
- Install package
- Setup service provider
- Generate a repository
- Add repository binding
- Example usage
- Namespace configuration
- Assumptions
- Default configuration
- Multiple configurations
- Specificity
- Available methods
- Stub customization
Changelog
View the changelog.
Usage
Install package
Setup service provider
This package is NOT loaded using package discovery. You should create your own service provider that extends the one from this package and add it to your config manually.
app/Providers/RepositoryServiceProvider.php
config/app.php
Generate a repository
This will create the following files:
MyModelRepositoryInterface.php
MyModelRepository.php
The namespace and file location depend on the namespace configuration.
Alternatively you can completely override the contract and repository FQN by using the command options. The namespace matching and class name suffixing will be skipped.
Add repository binding
Set up the binding of your new repository in the service provider.
Example usage
Publishing configuration file
Because this package does not register its own service provider, your own service provider should be referenced when publishing this package's configuration file.
Namespace configuration
The namespaces configuration is used to determine what the namespaces of your repository classes - and locations of the subsequent files - should be. Each configuration exists of three parts:
models
contracts
repositories
When generating a repository for a model the command will look for a namespace configuration which has a models
part that matches the supplied model.
The contracts
and repositories
parts of that configuration are then used as the namespaces for the repository classes.
Assumptions
- The namespaces follow the PSR-4 file location convention.
- The namespaces are within the Laravel app directory.
Default configuration
When generating a repository for App\Models\MyModel
, the following two classes will be created:
App\Contracts\Repositories\MyModelRepositoryInterface
App\Repositories\MyModelRepository
Multiple configurations
You can have multiple namespace configurations, for example when using domains.
Specificity
The first match will be used so if you have overlapping namespace configurations, make sure to have the more specific ones on top.
Available methods
See interface.
Stub customization
See Laravel's documentation about stub customization. This package adds the following stub files:
model.repository.interface.stub
model.repository.stub
PHPUnit
PHPStan
Credits
- wimski
- All Contributors
License
The MIT License (MIT). Please see License File for more information.