Download the PHP package propaysystems/laravel-base-repositories without Composer
On this page you can find all versions of the php package propaysystems/laravel-base-repositories. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download propaysystems/laravel-base-repositories
More information about propaysystems/laravel-base-repositories
Files in propaysystems/laravel-base-repositories
Package laravel-base-repositories
Short Description Base elequent repositories with interface for common queries.
License MIT
Homepage https://github.com/propaysystems/laravel-base-repositories
Informations about the package laravel-base-repositories
Base elequent repositories with interfaces for common queries.
UNDER DEVELOPMENT AND TESTING - WE WILL ADD PROPER DOCUMENTATION WITH v1 STABLE RELEASE
This is the base classes & helper commands for the repository pattern we use. In your own repository classes you have to extend the BaseRepository and implement your custom interface. In your custom interface you have to extend the BaseRepositoryInterface. This will give you a collection of commonly used queries and function that you don't need to duplicate each time.
Requirements
PHP 8.0+ \ Laravel 8+
Version Compatibility
Laravel | BaseRepositories |
---|---|
8.x | 0.0.7 |
9.x | 0.0.3 |
10.x | 0.0.8 |
Installation
You can install the package via composer:
You can publish the config file with:
Configuration
We create the service and repositories in the app folder of laravel to make use of laravels auto loading functionality.
Service
The default path for createing services will be in the App\Services
folder. If the folder does not exist it will be created.
If you want to overwrite default path for the service you can add a ENV
variable and specify your custom path.
The base name that will be appended to the class that is created by default, it will append Service
. So if you create a User -s
service the file that gets created will be UserService
Repository
The default path for createing repositories will be in the App\Repositories
folder. If the folder does not exist it will be created.
If you want to overwrite default path for the repository you can add a ENV
variable and specify your custom path.
The base name that will be appended to the class that is created by default, it will append Repository
. So if you create a User -r
service the file that gets created will be UserRepository
& UserRepositoryInterface
Usage
Creating a Service
The service class is where all the domain logic will be created. This makes it easier to reuse business logic in the controllers, API, commands etc
- Creating a service class:
Running this command will create a new service class in the App\Services\
folders.
The rule is to split every service into its own related folders so the above command will actually create a file in:
App\Services\Users\UserService.php
Injecting a Repository
:grey_exclamation: Remember to dependancy inject your repositories you want to use into the
__construct
method of your service like the example below.
Creating a Repository
- Creating a repository class:
Running this command will create a repository class with its related interface in the App\Repositories
& App\Repository\UserRepository\Interfaces
folder.
Specifying the model with auto link the relevant model to the repository. In this case the User model will be added to the construct methof of the repository.
Same as the service class the rule is to split each repository into its own related folders so the above command will create files in:
App\Repositories\Users\UserRepositories.php
App\Repositories\Users\Interfaces\UserRepositoriesInterface.php
This will also try create and register the class and interface in laravel.
:grey_exclamation: These command flags can be combined
-s -r
so that the related service and repository classes be created in one command.
First Repository
After creating your first repository a RepositoryServiceProvider.php
file will automatically be created in your App\Providers
folder. You will need to add
the repository provider file to your config/app.php
under the providers
section. This will tell laravel that you are adding repositories and linking interfaces
to them and they be autoloaded.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Ettienne Louw
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-base-repositories with dependencies
spatie/laravel-package-tools Version ^1.9.2
illuminate/contracts Version ^11.0