mehedi250/laravel-structure-kit
Installation
composer require mehedi250/laravel-structure-kit
php artisan structure:kit:install
Run the installer to publish assets (config, views, and migrations).
First Use Case Generate a Model + Controller + Migration + Service + Repository structure:
php artisan structure:make Post
This creates:
app/Models/Post.phpapp/Http/Controllers/PostController.phpdatabase/migrations/..._create_posts_table.phpapp/Services/PostService.phpapp/Repositories/PostRepository.phpWhere to Look First
config/structure-kit.php (customize paths, templates, and defaults).app/Console/Kernel.php (check registered commands).resources/views/structure-kit/ (customize blade templates for scaffolding).Scaffolding a Full CRUD Module
php artisan structure:make Post --resource --api
PostController with index, store, show, etc.).--api flag is used).structure-kit.php).Customizing File Paths
Override defaults in config/structure-kit.php:
'paths' => [
'models' => 'Domain/Models',
'services' => 'Domain/Services',
'repositories' => 'Domain/Repositories/Eloquent',
],
Now php artisan structure:make User places files in Domain/.
Extending with Custom Templates
vendor/mehedi250/laravel-structure-kit/resources/views/structure-kit/ to resources/views/structure-kit/.service.blade.php) to add custom methods or traits.Integrating with Existing Code
--force to overwrite existing files:
php artisan structure:make Post --force
php artisan structure:migration Post
UI Preview Mode
php artisan structure:kit:preview
http://your-app.test/structure-kit to visually design and export your project structure before generating files.php artisan db:seed after migration generation.--api flag and integrate with tools like Postman or Laravel Dusk.structure-kit.php and template overrides to version control.CONTRIBUTING.md for team consistency.# Example GitHub Actions step
- run: php artisan structure:make Feature --resource
Namespace Conflicts
Domain\Models), ensure autoloading is configured in composer.json:
"autoload": {
"psr-4": {
"Domain\\": "app/Domain/"
}
}
composer dump-autoload after changes.Template Overrides Not Loading
php artisan view:clear
resources/views/structure-kit/ (not resources/views/).Migration Conflicts
--force cautiously:
php artisan structure:migration Post --force
CLI Command Not Found
config/app.php:
'providers' => [
Mehedi250\StructureKit\StructureKitServiceProvider::class,
],
php artisan vendor:publish --provider="Mehedi250\StructureKit\StructureKitServiceProvider"
Enable Debug Mode
Set debug to true in config/structure-kit.php to log template rendering:
'debug' => env('STRUCTURE_KIT_DEBUG', false),
Check Generated Files
artisan structure:make --debug to see the full file generation process.storage/logs/ for logs).Common Errors
composer dump-autoload.php artisan view:clear.Custom Commands
Extend the package by creating a new artisan command in app/Console/Commands/ that uses the kit’s generator:
use Mehedi250\StructureKit\Generators\Generator;
class CustomGeneratorCommand extends Command {
protected $generator;
public function __construct(Generator $generator) {
parent::__construct();
$this->generator = $generator;
}
// ...
}
Dynamic Templates Use Laravel’s view composers to dynamically modify templates:
// app/Providers/StructureKitServiceProvider.php
public function boot() {
view()->composer('structure-kit::service', function ($view) {
$view->with('customMethod', 'customLogic()');
});
}
Hooks for Post-Generation
Listen for the structure.kit.generated event to run post-processing:
// app/Providers/EventServiceProvider.php
protected $listen = [
'structure.kit.generated' => [
'App\Listeners\PostGenerateListener',
],
];
Testing Mock the generator in PHPUnit tests:
$this->mock(Generator::class)->shouldReceive('generate')->once();
@include('structure-kit::partials/trait')) to avoid duplication.structure-kit.php to switch templates per environment:
'templates' => env('STRUCTURE_KIT_TEMPLATES', 'default'),
.gitignore if they’re environment-specific:
/app/Services/__generated__
'debug' => false).How can I help you explore Laravel packages today?