Laravel Maker: A Laravel Development Package for Creating Classes , Enums, Traits, Services Classes and more .
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:
You can install the package via composer:
composer require ammaraldwayma/laravel-maker --dev
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
{
}
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
{
//
}
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
{
//
}
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
{
//
}
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(),
];
}
}
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,
)
{
//
}
}
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',
],
];
composer test
Please see CHANGELOG for more information on what has changed recently.
The MIT License (MIT). Please see License File for more information.