xethron/laravel-4-generators
Scaffolding generators for Laravel 4. Quickly create controllers, models, migrations, views and other boilerplate from Artisan commands to speed up CRUD and app setup, reducing repetitive work and keeping projects consistent.
Installation
composer require xethron/laravel-4-generators
php artisan vendor:publish --provider="Xethron\Generators\GeneratorsServiceProvider"
config/generators.php.First Use Case: Generate a CRUD Resource
php artisan generate:all Post
app/Models/Post.php)database/migrations/..._create_posts_table.php)app/Http/Controllers/PostController.php)resources/views/posts/*)Where to Look First
php artisan to see available generators (e.g., generate:model, generate:controller, generate:all).config/generators.php.resources/views/vendor/generators/stubs/ (publish them first with php artisan vendor:publish --tag=generators.stubs).Rapid CRUD Scaffolding
generate:all for full-stack CRUD:
php artisan generate:all User --fields="name,email,password"
resources/views/ post-generation.Modular Generation
php artisan generate:model Product --migration --factory
php artisan generate:controller Product --resource
Custom Field Handling
php artisan generate:model Article --fields="title,content,published_at:datetime"
string, text, integer, boolean, datetime).Integration with Existing Code
class Post extends \Xethron\Generators\Eloquent\Model {
public function comments() { return $this->hasMany(Comment::class); }
}
PostController:
public function store(Request $request) {
$validated = $request->validate(['title' => 'required|unique:posts']);
return parent::store($validated);
}
Testing
php artisan generate:factory User
public function test_create_post() {
$response = $this->post('/posts', ['title' => 'Test']);
$response->assertRedirect('/posts');
}
Laravel 5+ Compatibility:
--force to overwrite files if needed:
php artisan generate:all Post --force
ApiResource:
php artisan generate:controller Post --api
View Customization:
resources/views/posts/partials/_form.blade.php.resources/views/layouts/app.blade.php.Database-Specific Features:
$table->json('metadata')->nullable();
--table to specify an existing table:
php artisan generate:model Post --table=blog_posts
Automation:
php artisan generate:all User && php artisan generate:all Post
Laravel Version Mismatch
illuminate/support).Outdated Stubs
resources/views/vendor/generators/stubs/:
php artisan vendor:publish --tag=generators.stubs
@extends('app') with @extends('layouts.app') for Laravel 5.4+.No API Resource Support
ApiResource.make:resource for API endpoints.Hardcoded Routes
Route::get('posts', 'PostController@index')).Route::resource() in routes/web.php post-generation.Factory Quirks
Faker changes).make:factory for new projects.No Test Generation
phpunit templates.config/app.php:
'providers' => [
Xethron\Generators\GeneratorsServiceProvider::class,
],
config/generators.php:
'stubs' => [
'model' => resource_path('views/vendor/generators/stubs/model.stub'),
],
order) in field names. Use --table to specify an existing table if needed.config/generators.php:
'paths' => [
'models' => app_path('Domain/Models'),
'migrations' => database_path('migrations/custom'),
],
'naming' => [
'singular' => 'Post',
'plural' => 'Posts',
],
config/generators.php:
'fields' => [
'created_at' => 'timestamp',
'updated_at' => 'timestamp',
],
Custom Stubs
model.stub, controller.stub).ApiResource support to controller stubs.Post-Generation Hooks
register method in GeneratorsServiceProvider to add logic after generation:
public function register() {
$this->app->afterResolving('generators', function ($generators) {
// Run custom logic post-generation
});
}
Command Extensions
GenerateAllCommand):
class CustomGenerateAllCommand extends GenerateAllCommand {
protected function getFields() {
return ['title' => 'string', 'slug' => 'string'];
}
}
Integration with Laravel Mix
webpack.mix.js:
mix.postCss('resources/css/app.css', 'public/css', [
require('postcss-import'),
]);
xethron/laravel-4-generators for legacy projects and laravel-shift/generators for new ones..gitignore if using dynamic names:
/resources/views/posts/*
php artisan generate:all User in deploy.sh).README.md for each module:
echo "# Post Module" > docs/posts.md && php artisan generate:all Post >> docs/posts.md
How can I help you explore Laravel packages today?