ammaraldwayma / laravel-maker
Laravel Maker is a powerful Laravel package designed to elevate your development experience by introducing a set of custom Artisan commands. These commands are meticulously crafted to simplify and expedite the creation of essential components in your Laravel application, fostering a more efficient a
Fund package maintenance!
AmmarNassar
Requires
- php: ^8.1
- illuminate/contracts: ^10.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- larastan/larastan: ^2.0.1
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8
- pestphp/pest: ^2.20
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
README
Laravel Maker is a powerful Laravel development package designed to help you to enhance your development process by creating Classes , Enums, Traits, Interfaces, Services and more with a single command.
With Laravel Maker you can create the following classes:
Installation
You can install the package via composer:
composer require ammaraldwayma/laravel-maker --dev
Usage
Creating a new Class
php artisan make:class Actions/StoreUserAction
This command will create a new class in the app/Actions
directory. The class will be named StoreUserAction
and will
contain the following code:
<?php namespace App\Actions; class StoreUserAction { }
Creating a new Enum
php artisan make:enum Statuses
This command will create a new enum class in the app/Enums
directory. The class will be named Statuses
and will
contain the following constants:
<?php namespace App\Enums; enum Statuses: string { // }
Creating a new Trait
php artisan make:trait HasStatus
This command will create a new trait class in the app/Traits
directory. The class will be named HasStatus
and will
contain the following code:
<?php namespace App\Traits; trait HasStatus { // }
Creating a new Interface
php artisan make:interface UserRepositoryInterface
This command will create a new interface class in the app/Interfaces
directory. The class will be
named UserRepository
and will contain the following code:
<?php namespace App\Interfaces; interface UserRepositoryInterface { // }
Creating a new Service / Third-party Service
php artisan make:service GoogleTranslationService
This command will create a new service class in the app/Services
directory. The class will be
named GoogleTranslationService
and will contain the following code:
<?php namespace App\Services; class GoogleTranslationService { /** * @param PendingRequest $httpClient * @param array $serviceKeys */ public function __construct( protected PendingRequest $httpClient, protected array $serviceKeys = [], ) { $this->serviceKeys = config('services.google_translation'); $this->httpClient = Http::asJson() ->acceptJson() ->withoutVerifying() ->baseUrl($this->serviceKeys['base_url']) ->timeout($this->serviceKeys['timeout']); } /** * Get {{ name }} data . * * @param array $data * @return array */ public function get(array $data = []): array { $response = $this->httpClient->get('/'); if ($response->failed()) { return [ 'status' => false, 'data' => [], ]; } return [ 'status' => true, 'data' => $response->json(), ]; } }
Creating a new Repository
php artisan make:repo UserRepository
This command will create a new repository class in the app/Repositories
directory with a interface class in the
app/Repositories/Interfaces
directory. The class will be named UserRepository
and will contain the following code:
<?php namespace App\Repositories; use App\Repositories\Interfaces\UserRepositoryInterface; use App\Models\User; class UserRepository implements UserRepositoryInterface { /** * @param User $user */ public function __construct( protected User $user, ) { // } }
Customizing the default namespaces
You can customize the default namespaces for the different types of classes that you can generate it by the package by
- Publishing the config file:
php artisan vendor:publish --tag="maker-config"
- Changing the values of the
default_namespaces
array in the published config file:
return [ /* |-------------------------------------------------------------------------- | Default Namespaces |-------------------------------------------------------------------------- | Here you can specify the default namespaces for the different types of | classes that you can generate it by the package. | */ 'default_namespaces' => [ 'enum' => 'App\Enums', 'trait' => 'App\Traits', 'interface' => 'App\Interfaces', 'service' => 'App\Services', 'repository' => 'App\Repositories', ], ];
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.