prevailexcel / laravel-action-service-trait
A simple Laravel package to create actions, traits and services using artisan commands
Requires
- php: ^7.1|^8.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-12-24 21:48:21 UTC
README
A Simple Package to create actions, traits and services using artisan commands in laravel.
This package extends the make:
commands to help you easily create traits, action classes and service classes in Laravel 5+. It also comes with the option of creating an interface for the service.
Install
composer require prevailexcel/laravel-action-service-trait
Or add the following line to the require block of your composer.json
file.
"prevailexcel/laravel-action-service-trait": "1.0.*"
You'll then need to run composer install
or composer update
to download it and have the autoloader updated.
Once it is installed, you can use any of the commands in your terminal.
Usage
php artisan make:action {name}
php artisan make:service {name}
php artisan make:service {name} --i
php artisan make:trait {name}
Examples
Create an action class
$ php artisan make:action CreateUser
/app/Actions/CreateUser.php
<?php namespace App\Actions; /** * Class CreateUser * @package App\Services */ class CreateUser { /** * @return true */ public function execute(){ // write your code here return true; } }
Create a service class with interface
php artisan make:service PostService --i
/app/Services/PostService.php
<?php namespace App\Services; use App\Services\Interfaces\PostServiceInterface; /** * Class PostService * @package App\Services */ class PostService implements PostServiceInterface { }
Then the interface would look like this
/app/Services/Interfaces/PostUserInterface.php
<?php namespace App\Services\Interfaces; /** * Interface PostServiceInterface * @package App\Services\Interfaces */ interface PostServiceInterface { }
Create a php trait
/app/Traits/UploadImage.php
$ php artisan make:trait UploadImage
<?php namespace App\Traits; /** * Trait UploadPhoto * @package App\Traits */ trait UploadPhoto { }
Contributing
Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.
How can I thank you?
Why not star the github repo? I'd love the attention! Why not share the link for this repository on Twitter or HackerNews? Spread the word!
Don't forget to follow me on twitter! Also check out my page on medium to catch articles and tutorials on Laravel follow me on medium!
Thanks! Chimeremeze Prevail Ejimadu.
License
The MIT License (MIT). Please see License File for more information.