laralearn / larastructor
An artisan companion for Laravel learners to create Models, Services, and Repositories.
dev-master
2025-04-22 15:39 UTC
Requires
- php: ^8.0
- illuminate/support: ^9.0|^10.0|^11.0
This package is auto-updated.
Last update: 2025-05-23 20:23:31 UTC
README
A set of Artisan commands to automatically generate Repository, Interface, and Service classes in your Laravel application with clean structure and naming conventions. Inspired by clean architecture β made simple and fun!
π Requirements
- Laravel 8 or above
- PHP 8.0+
- Your model classes should exist before running repository generation
ποΈ Generated Folder Structure Example
app/
βββ Models/
β βββ Product.php
βββ Repositories/
β βββ ProductRepository.php
β βββ Interfaces/
β βββ ProductRepositoryInterface.php
βββ Services/
β βββ ProductService.php
π Installation
composer require laralearn/larastructor
π Available Commands
- β Make a Model
php artisan larastruct:make-model
You'll be prompted for:
Model name
Table name
Fillable fields
Hidden fields
Soft delete support
What it does:
Checks if the model already exists in the given path
Creates a model file inside app/Models
2. β Generate Repository & Interface
php artisan larastruct:make-repository {model} --model-path=Models
Options:
model β The name of your model (e.g. Product)
--model-path β Relative path to your model directory (default: Models)
What it does:
Checks if the given model exists in the specified path
Creates:
ProductRepository.php in app/Repositories
ProductRepositoryInterface.php in app/Repositories/Interfaces
Adds boilerplate CRUD methods
3. β Generate Service Class for Repository
Options:
repository β The name of your repository/model (e.g. Product)
--repository-path β Relative path to your repositories (default: Repositories)
What it does:
Checks if the repository and interface exist
Creates a service class in app/Services
Injects the interface in the constructor
Adds methods: getAll, getById, create, update, delete
4. β Generate Service Class for Model
php artisan larastruct:make-service {model} --model-path=Models
Options:
model β The name of your model (e.g. Product)
--model-path β Relative path to your model directory (default: Models)
What it does:
Checks if the model exists
Creates a service class in app/Services
Injects the model in the constructor
Adds basic methods like getAll, getById, create, update, delete
π§ͺ Example Output
ProductRepository
class ProductRepository
{
public function all() { ... }
public function find($id) { ... }
public function create(array $data) { ... }
public function update($id, array $data) { ... }
public function delete($id) { ... }
}
β¨ Contribution
Want to improve this tool or add new features? Feel free to fork and submit a PR. Letβs make LaraStructor even cooler together π
Author(s)
- @lokeshrangani
- waiting for second name