anwar / crud-generator
A powerful Laravel package for generating CRUD operations with advanced UI, validation, API generation, and comprehensive testing support. Database-safe with manual migration control.
Installs: 65
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Language:Blade
Requires
- php: ^8.1
- illuminate/console: ^10.0|^11.0
- illuminate/database: ^10.0|^11.0
- illuminate/routing: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
- illuminate/view: ^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.0
README
A powerful Laravel package that automates the creation of CRUD operations with advanced features including API generation, comprehensive validation support, and modern UI interface.
๐จ Important Safety Notice
โ ๏ธ ALWAYS BACKUP YOUR DATABASE BEFORE INSTALLATION
This package includes migrations. For your safety:
- Migrations are NOT automatically run
- You must manually publish and review them
- See SAFETY-NOTICE.md for complete safety guidelines
โจ Features
- ๐ Complete CRUD Generation - Models, Controllers, Views, Migrations, Requests, Resources
- ๐จ Modern UI Interface - Bootstrap 4 with live preview and advanced field configuration
- โ Full Validation Support - All Laravel validation rules with visual builder
- ๐ API Generation - RESTful controllers and JSON resources
- ๐ Auto Documentation - Generate API docs in Markdown and HTML
- โก CLI Integration - Artisan commands for automation
- ๐งช Test Generation - Feature and unit tests included
- ๐ฏ Customizable Templates - Stub-based system for full customization
- ๐ก๏ธ Database Safe - No automatic migrations, full user control
๐ Requirements
- PHP 8.1 or higher
- Laravel 10.0 or higher
- MySQL 5.7+ or PostgreSQL 10+
๐ Quick Start
Safe Installation
# 1. BACKUP YOUR DATABASE FIRST! mysqldump -u user -p database_name > backup.sql # 2. Install the package composer require anwar/crud-generator # 3. Publish assets (migrations will NOT auto-run) php artisan vendor:publish --tag=crudgenerator-config php artisan vendor:publish --tag=crudgenerator-migrations php artisan vendor:publish --tag=crudgenerator-assets # 4. Review published migrations first! ls database/migrations/*anwar* # 5. Only run if safe php artisan migrate
Access the Generator
Visit: http://your-app.com/admin/anwar-crud-generator
๐ฏ Usage Examples
Web Interface
-
Access the Generator Interface
http://your-app.com/admin/anwar-crud-generator
-
Configure Your Module
- Module Name:
Post
- Fields:
title
(string, required|max:255)content
(text, required)status
(boolean)published_at
(datetime, nullable)
- Relationships:
user
(belongsTo User)comments
(hasMany Comment)
- Options: โ API, โ Soft Deletes
- Module Name:
-
Preview and Generate
- Use live preview to review generated code
- Click "Generate" to create all files
CLI Commands
# Generate via Artisan php artisan anwar-crud:generate Post \ --fields="title:string,content:text,status:boolean" \ --relationships="user:belongsTo" \ --api \ --soft-deletes # List generated modules php artisan anwar-crud:list # Delete module php artisan anwar-crud:delete Post --force
API Usage
# Generate via API curl -X POST http://your-app.com/api/crud-modules \ -H "Content-Type: application/json" \ -H "Authorization: Bearer your-token" \ -d '{ "module": "Product", "fields": "name:string,price:decimal,description:text", "relationships": "category:belongsTo", "api": true, "softdeletes": false }' # List modules curl -X GET http://your-app.com/api/crud-modules \ -H "Authorization: Bearer your-token"
๐ Generated Files
When you generate a Post
module, you'll get:
app/
โโโ Models/Post.php # Eloquent model with relationships
โโโ Http/
โ โโโ Controllers/
โ โ โโโ PostController.php # Web controller
โ โ โโโ Api/PostController.php # API controller
โ โโโ Requests/PostRequest.php # Form validation
โ โโโ Resources/PostResource.php # API resource
resources/views/posts/ # Bootstrap 4 views
โโโ index.blade.php # List view with DataTables
โโโ create.blade.php # Create form
โโโ edit.blade.php # Edit form
โโโ show.blade.php # Detail view
database/migrations/
โโโ create_posts_table.php # Database migration
tests/
โโโ Feature/PostTest.php # Feature tests
โโโ Unit/PostTest.php # Unit tests
๐จ Advanced Features
Field Types & Validation
Support for all Laravel field types and validation rules:
'fields' => [ ['name' => 'email', 'type' => 'string', 'validation' => 'required|email|unique:users'], ['name' => 'age', 'type' => 'integer', 'validation' => 'required|integer|min:18|max:65'], ['name' => 'bio', 'type' => 'text', 'validation' => 'nullable|string|max:1000'], ['name' => 'avatar', 'type' => 'string', 'validation' => 'nullable|image|max:2048'], ['name' => 'settings', 'type' => 'json', 'validation' => 'nullable|array'], ['name' => 'salary', 'type' => 'decimal', 'validation' => 'required|numeric|min:0'], ]
Complex Relationships
'relationships' => [ [ 'name' => 'user', 'type' => 'belongsTo', 'model' => 'User', 'foreign_key' => 'user_id' ], [ 'name' => 'tags', 'type' => 'belongsToMany', 'model' => 'Tag', 'pivot_table' => 'post_tags' ] ]
API Features
Generated API controllers include:
- โ RESTful endpoints (GET, POST, PUT, DELETE)
- โ JSON API resources with data transformation
- โ Proper HTTP status codes
- โ Error handling and validation
- โ Pagination support
- โ Rate limiting ready
Example API endpoints:
GET /api/posts # List all posts
POST /api/posts # Create new post
GET /api/posts/{id} # Get specific post
PUT /api/posts/{id} # Update post
DELETE /api/posts/{id} # Delete post
๐ง Configuration
Customize the package behavior in config/anwarcrud.php
:
return [ 'model_namespace' => 'App\\Models', 'controller_namespace' => 'App\\Http\\Controllers', 'view_path' => 'resources/views', 'features' => [ 'api_generation' => true, 'test_generation' => true, 'documentation_generation' => true, 'soft_deletes' => true, ], 'ui' => [ 'theme' => 'bootstrap4', 'show_preview' => true, 'enable_live_preview' => true, ], ];
๐ฏ Customization
Custom Templates
-
Publish stubs:
php artisan vendor:publish --tag=anwar-crud-stubs
-
Modify templates in
resources/crud-stubs/
-
Use custom placeholders:
@modelName
- Model class name@modelVar
- Model variable name@fields
- Generated fields@relationships
- Generated relationships
Custom Field Types
Add custom field types:
'custom_fields' => [ 'phone' => [ 'migration_type' => 'string', 'validation' => 'required|string|regex:/^[0-9\-\+\s\(\)]+$/', 'input_type' => 'tel' ] ]
๐งช Testing
Run package tests:
vendor/bin/phpunit packages/CrudGenerator/tests/
Generated modules include comprehensive tests:
// Feature Test Example public function test_can_create_post() { $data = ['title' => 'Test Post', 'content' => 'Test Content']; $response = $this->post(route('posts.store'), $data); $response->assertRedirect(route('posts.index')); $this->assertDatabaseHas('posts', $data); } // API Test Example public function test_api_can_list_posts() { Post::factory(3)->create(); $response = $this->getJson('/api/posts'); $response->assertOk() ->assertJsonCount(3, 'data'); }
๐ Documentation
- Full Documentation: DOCUMENTATION.md
- API Reference: Complete API documentation with examples
- Video Tutorials: [Coming Soon]
- Wiki: GitHub Wiki
๐ค Contributing
We welcome contributions! Please see CONTRIBUTING.md for details.
Development Setup
git clone https://github.com/ringkubd/crud-generator.git
cd crud-generator
composer install
cp .env.example .env.testing
php artisan key:generate --env=testing
vendor/bin/phpunit
๐ Bug Reports & Feature Requests
Please use GitHub Issues for:
- ๐ Bug reports
- ๐ก Feature requests
- ๐ Documentation improvements
- โ Questions and support
๐ License
This package is open-source software licensed under the MIT License.
๐ Credits
- Author: Anwar Jahid | ajr.jahid@gmail.com
- Contributors: All Contributors
- Inspired by: Laravel community and best practices
๐ Links
- Packagist: anwar/crud-generator
- GitHub: ringkubd/anwarcrud
- Issues: Report Issues
- Discussions: GitHub Discussions
โญ Star this repo if you find it useful!
Made with โค๏ธ for the Laravel community