dev-master
9999999-devProvide command line generation of service layer files.
MIT
The Requires
- php >=5.4.0
- illuminate/support ~5.0
by James Bennett
laravel services generators
Wallogit.com
2017 © Pedro Peláez
Provide command line generation of service layer files.
A command line tool for generating service layer files for your application. Inspired by Jeffrey Way's L5 generator packages., (*1)
The generator provided in this package is aimed to reduce time spent on boilerplate code when using a service layer within laravel. Although it allows for use without, the main aim is to be used in conjunction with a repository., (*2)
Install the package using composer, (*3)
composer require maltex/laravel-service-generators
Make the package available to your application by adding the service provider. This is not required for production code so register it by adding the following to your app/Providers/AppServiceProvider.php:, (*4)
public function register()
{
if ($this->app->environment() == 'local') {
$this->app->register('Maltex\Generators\GeneratorsServiceProvider');
}
}
Let's say you're working with a Client model. You've created your front end screen, your routes and a controller end-point. Now we need to manage the business logic., (*5)
php artisan make:service AddClientService --repo=Client --func=addClient, (*6)
You will see that a Services folder is now available in your application with the AddClientService.php file., (*7)
use Maltex\Generators\Contracts\ServiceContract; use App\Repositories\CLientRepository; class AddClientService implements ServiceContract { /** * @var App\Repositories\ClientRepository */ protected $repository; /** * Inject the repository * * @return void */ public function __construct(App\Repositories\ClientRepository $repository) { $this->repository = repository; } /** * @inheritdoc */ public function execute($data) { // TODO Add business logic $this->repository->addClient($data) } }
This service should then be injected into your controller function., (*8)
// ClientController.php
public function create(
Request $request,
AddClientService $service
)
{
if($service->execute($request)) {
// success response
}
}
Provide command line generation of service layer files.
MIT
laravel services generators