The Laravel Make Extended package provides additional make:
commands that simplify common development tasks in Laravel, such as creating actions, DTOs (Data Transfer Objects), repositories, services, and more. This package aims to fill gaps in Laravel's built-in Artisan commands, offering enhanced tools to streamline development.
Developed to boost productivity and maintain code organization, these commands provide structure and separation of concerns for complex Laravel applications.
- Enhanced
make:
commands: Adds useful Artisan commands likemake:action
,make:dto
,make:repository
, andmake:service
. - Separation of concerns: Promotes clean architecture patterns like CQRS and DDD (Domain-Driven Design) by offering DTOs, actions, and repositories.
- Extendable: Easily customizable stubs for generated files. See the Customizing Stubs section for more information.
- Seamless integration: Works seamlessly with existing Laravel projects from version 9.x onwards.
To install the Laravel Make Extended package, follow these steps:
-
Install via Composer:
Run the following command to install the package via Composer:
composer require evotic/make-extended
-
Publish Configuration (Optional):
If you want to customize any aspect of the package, you can publish the configuration files:
php artisan vendor:publish --tag=make-extended-config
Once the package is installed, you can start using the new make:
commands in your Laravel project.
For example, to create a new action class, simply run:
php artisan make:action YourAction
Each generated file will be placed in the appropriate folder, following Laravel’s naming conventions.
This package provides the following make:
commands:
Creates a single-action class, which can be used to organize your business logic and simplify controllers. Typically used in a CQRS pattern.
php artisan make:action ProcessOrderAction
This generates the following file:
// app/Actions/ProcessOrderAction.php
namespace App\Actions;
class ProcessOrderAction
{
public function __invoke()
{
//
}
}
Single-action classes can be useful for organizing logic that```s reused across different parts of your application (such as processing an order, user registration, etc.).
Generates a Data Transfer Object (DTO) class. DTOs are used to encapsulate data that is passed between layers of the application.
php artisan make:dto UserDto
This generates the following file:
// app/DTOs/UserDto.php
namespace App\DTOs;
class UserDto
{
public function __construct(
//
) {}
// Add your methods here
}
DTOs are used to carry data between different layers of the application (e.g., from a controller to a service) while ensuring that the data structure is consistent and immutable.
Creates a Repository class, useful for abstracting data access logic. Repositories are often used in service layers to handle database operations, ensuring that the domain logic is decoupled from the data source.
php artisan make:repository UserRepository
This generates the following file:
// app/Repositories/UserRepository.php
namespace App\Repositories;
class UserRepository
{
public function all()
{
// Fetch all users
}
public function find($id)
{
// Find a user by ID
}
public function create(array $data)
{
// Create a new user
}
public function update($id, array $data)
{
// Update an existing user
}
public function delete($id)
{
// Delete a user
}
}
Repositories provide an abstraction layer between the business logic and the database, allowing developers to swap out the data source without affecting the rest of the application.
Creates a Service class. Services contain the business logic of the application and typically call repositories or other services to perform their operations.
php artisan make:service PaymentService
This generates the following file:
// app/Services/PaymentService.php
namespace App\Services;
class PaymentService
{
public function __construct()
{
//
}
// Add your methods here
}
Service classes are useful for isolating business logic, making it easier to maintain, test, and reuse across different parts of the application.
If you need to customize the stubs generated by the make:
commands, you can publish the stubs to your Laravel project by running:
php artisan vendor:publish --tag=make-extended-stubs
This will publish the stubs to the resources/stubs/make-extended
directory in your Laravel application. You can then modify these stubs as needed, and the package will use the customized stubs instead of the default ones.
To customize the Service.stub
, you would find the file at: resources/stubs/make-extended/Service.stub
.
If you'd like to contribute to this project, feel free to submit pull requests or open issues on GitHub. Contributions, suggestions, and improvements are always welcome!
- evotic Website: evotic.io
- Laravel Documentation: Laravel Docs
- CQRS Pattern: CQRS Documentation
- Data Transfer Objects (DTOs): DTO Pattern
This package is licensed under the MIT License. See the LICENSE file for more information.