rschaaphuizen / laravel-services
Package to create services with artisan
Requires
- php: ^7.0
This package is not auto-updated.
Last update: 2025-06-19 19:19:49 UTC
README
This Laravel package creates an artisan command to generate services.
php artisan make:service NameService
Optionally, you can create the service as an abstract class by adding the option:
php artisan make:service NameService --abstract
Register the created Service in the ServiceProvider (ex ServicesServiceProvider)
<?php namespace App\Providers; use App\Services\NameService; use Illuminate\Support\ServiceProvider; class ServicesServiceProvider extends ServiceProvider { /** * Bootstrap the application services. * * @return void */ public function boot() { // } /** * Register the application services. * * @return void */ public function register() { $this->app->bind('NameService', function ($app) { return new NameService(); }); } }
Registering the Service is not needed if the Service is created as an abstract class
Inject your service through your constructor of the desired controller
<?php namespace App\Http\Controllers; use App\Services\NameService; use Illuminate\Http\Request; class ExampleController extends Controller { /** * @var NameService */ protected $nameService; /** * ExampleController constructor. * @param NameService $nameService */ public function __construct(NameService $nameService) { $this->nameService = $nameService; } // the rest of your controller }
Installation and usage
This package requires PHP 7 and Laravel 5.5 or higher. Install the package by running the following command in your console;
composer require rschaaphuizen/laravel-services
Changelog
Please see CHANGELOG for more information what has changed recently.
Security
If you discover any security-related issues, please email r.schaaphuizen@sqits.nl instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.