Package Data | |
---|---|
Maintainer Username: | wskyjames |
Maintainer Contact: | james@maltex.com (James Bennett) |
Package Create Date: | 2016-09-02 |
Package Last Update: | 2016-12-15 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-19 03:21:57 |
Package Statistics | |
---|---|
Total Downloads: | 13 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 4 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 0 |
A command line tool for generating service layer files for your application. Inspired by Jeffrey Way's L5 generator packages.
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.
Install the package using composer
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
:
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.
php artisan make:service AddClientService --repo=Client --func=addClient
You will see that a Services folder is now available in your application with the AddClientService.php file.
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.
// ClientController.php
public function create(
Request $request,
AddClientService $service
)
{
if($service->execute($request)) {
// success response
}
}