Downloads
Stars
Version
This is an open source Laravel package which is intended primarily for those developers who uses the layered structure, like:
model - repository - service - controller
or
model - service - controller
.
Actually, the package allows to create any classes, interfaces, traits that you want.
composer require si-dev/laravel-layered
Then run command:
php artisan vendor:publish --provider="SiDev\LaravelLayered\LayeredServiceProvider"
Package will use its own base repository and service classes and interfaces, but if you want to use yours, you can redefine them in config/layered.php.
creates a contract (interface) with the given name. It is also possible to specify an extensible interface.
Options
-e, --extends=EXTENDS
creates a contract that extends another specified contract
Note: the contract that extends will not be created
php artisan make:contract ProductInterface
php artisan make:contract ProductInterface --extends=AdapterInterface
creates a class with the specified name. Using options you can create class with injected dependency and/or implementing the specified interface.
Options
-c, --contract[=CONTRACT]
If the name of the contract is specified, the command will create an interface with the specified name and a class that implements the created interface. Otherwise, a contract with the default name (classname + Interface) will be created and a class that implements the created interface.
-d, --dependency=DEPENDENCY
creates a class with the specified name and injects the specified dependency into the constructor.
--dependencyName=DEPENDENCYNAME
this option can only be used with the dependency
option. Used if you want to name the injection dependency variable with a different name.
Note:
dependency
anddependencyName
will not create a dependency (class or interface). You should create it manually or using command.
php artisan make:class Adapters/DocumentAdapter
php artisan make:class Adapters/DocumentAdapter -c
php artisan make:class Adapters/DocumentAdapter -c -dDocument
php artisan make:class Adapters/DocumentAdapter --dependency=DocumentInterface --dependencyName=document
creates a repository with the specified name. It also allows to extends base repository class, create and implement contract, inject the specified model.
Options
-e, --extends[=EXTENDS]
extends the specified class. If the name of the class to extend is not defined, it extends the base repository class that defined in package config.
-m, --model=MODEL
inject the model you specify. Note: the model will not be created, you should create it with appropriate command or manually.
-c, --contract
creates and implements the contract for the repository class
All repositories will be placed in the directory
App\Repositories
. All contracts you can find in the folderApp\Contracts\Repositories
.
php artisan make:repository ProductRepository
php artisan make:repository ProductRepository -c
php artisan make:repository ProductRepository -c -e
php artisan make:repository ProductRepository -c -e --model=Product
Base repository interface and class contain the next methods:
In addtition base repository class has magic __call
method. So you can use any Eloquent model method you need.
creates service class in the App\Services
folder. Also you can inject repository or model, extends base service class, implement contract.
Options
-e, --extends[=EXTENDS]
extends the specified class. If the name of the class to extend is not defined, it extends the base service class that defined in package config.
-r, --repository[=REPOSITORY]
injects repository class or interface.
-m, --model[=MODEL]
injects the specified model.
Notice: you can use either the repository or the model, but not both options together.
-c, --contract
creates and implements the contract for the service class
php artisan make:service ProductService
php artisan make:service ProductService --model=Product
php artisan make:service ProductService -c
php artisan make:service ProductService -c -e
php artisan make:service ProductService -c -e --repository=ProductRepository
creates bunch of classes for layered structure. As the result the next ones will be created:
Notice this command only creates contracts and classes, but does not bind abstract to concrete implementation. You should do it manually in AppServiceProvider or other service provider!
php artisan make:layered-bunch Product
creates a trait with the specified name. There is no custom options for this command.
php artisan make:trait Taggable
laravel-layered is open-source package licensed under the MIT license