mehedi250/laravel-structure-kit
To begin leveraging Laravel Structure Kit in your daily workflow, follow these minimal steps:
Installation:
composer require mehedi250/laravel-structure-kit
No additional configuration is required due to Laravel’s auto-discovery.
First Use Case:
http://localhost:8000/structure-kit in your browser.Product).Model, Controller, Service Pattern, Repository Pattern).For CLI users, run:
php artisan structure-kit Product mcsr
This generates a Model, Controller, Service, and Repository for Product.
Feature Development:
Team Onboarding:
app/Services/Implementations).Refactoring:
php artisan structure-kit User s --dry-run
Preview the Service layer before applying it to production code.Migration Management:
Testing:
*ServiceInterface.php, *RepositoryInterface.php) to mock dependencies in unit tests.public function test_product_service_creates_product()
{
$mockRepo = Mockery::mock(ProductRepositoryInterface::class);
$service = new ProductService($mockRepo);
// ...
}
| Scenario | Recommended Approach | Why? |
|---|---|---|
| Rapid prototyping | UI | Visual preview and one-click generation save time. |
| CI/CD pipelines | CLI (php artisan structure-kit) |
Scriptable and reproducible. |
| Team-wide conventions | UI (with "Remember paths") | Ensures consistency without manual configuration. |
| Custom templates | CLI (extend package) | More control over generated code via custom flags or templates. |
php artisan structure-kit User mcsr
php artisan structure-kit Product s --namespace="App\Services\Search"
Namespace Collisions:
app/Services/Custom), ensure the namespace in the generated file matches the directory.--namespace flag in CLI or manually edit the namespace line in the UI preview.Migration Conflicts:
--dry-run to preview or manually merge migrations.Service/Repository Overrides:
--force (if available in future versions).PHP Version Mismatch:
UI Caching:
git diff to compare changes before committing:
git diff --name-only
-v for detailed output:
php artisan structure-kit Product mcsr -v
.env:
APP_DEBUG=true
Custom Templates:
php artisan vendor:publish --tag=structure-kit-views
resources/views/vendor/structure-kit/ to change generated file stubs.Additional Flags:
--with-tests) by modifying the GenerateCommand class in the package’s source.Event Listeners:
structure-kit.generated event to post-process files:
use Mehedi250\StructureKit\Events\FilesGenerated;
public function handle(FilesGenerated $event)
{
// Add custom logic, e.g., run migrations or seed data
}
app/Domain/User/Services/) may slow down the UI.
Workaround: Use CLI for bulk operations.storage/) and bootstrap/cache/ are writable:
chmod -R 775 storage bootstrap/cache
# In a Forge deployment hook
php artisan structure-kit User mcsr --namespace="App\Modules\User"
php artisan structure-kit Product mcsr && php artisan ide-helper:generate
STRUCTURE.md file in your repo to explain the conventions enforced by the package:
## Project Structure
- All Services must implement `App\Services\Contracts\*Interface`.
- Repositories live in `app/Repositories/Eloquent/` and extend `BaseRepository`.
How can I help you explore Laravel packages today?