Generate your entire Laravel CRUD stack with one Artisan command
TL;DR — composer require bouda/laravel-make-pattern → php artisan make:pattern Post → 9 consistent files in seconds. DDD-ready, rollback included, every stub is yours to override. The problem I kept running into Every new Laravel project starts the same way. You know the architecture you want: Repository, Service, Controller, some Form Requests, a Resource, a Policy, a test. You've written this…
A Laravel developer has created a tool called laravel-make-pattern that allows users to generate a complete CRUD stack with just one Artisan command. This tool saves time and reduces errors by providing consistent, well-structured code for a clean, layered architecture.
The command `php artisan make:pattern Post` generates nine files, including the model, repository, service, controller, form requests, resource, policy, and test. These files are consistently named and follow the same conventions. The generated code is real, runnable code, not just empty stubs.
One of the key features of this tool is its support for Domain-Driven Design (DDD). By using the `--domain` flag, users can specify a namespace for the generated code, such as `app/Domain/Blog/`. This ensures that the generated files are organized according to the DDD principles.
Users can also customize the root namespace for the generated files using the `--namespace` flag. For example, using `php artisan make:pattern Post --namespace=Acme` will generate files with the namespace `Acme\Models\Post`, `Acme\Services\PostService`, etc.
The tool allows users to generate only the files they need by specifying which components to create, such as `--only=repository,service,controller`. This saves time when you already have a model and only need the other parts of the stack.
In addition, the tool includes rollback support, allowing users to undo the last generated pattern. This is useful in case any changes need to be reverted or if the generated code needs to be modified. The audit log can be accessed using `php artisan make:pattern:history` to view the history of all generated patterns.
The repository generated by this tool includes error logging, which can be enabled in the configuration file `config/make-pattern.php`. This feature logs any errors that occur during the execution of the repository's methods, helping developers to quickly identify and fix issues.
Primary key strategy is also customizable through the configuration file. Users can choose from various strategies, such as 'ulid', 'uuid', or 'increment', depending on their specific requirements.
Installation of the laravel-make-pattern tool is straightforward, requiring only the command `composer require bouda/laravel-make-pattern`. The tool is ready to use after installation, with no additional registration needed.
Overall, laravel-make-pattern provides a powerful solution for generating a complete CRUD stack in Laravel, offering consistency, DDD support, customizability, and rollback capabilities, making the development process faster and more efficient.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.