Installation
composer require ibex/crud-generator
php artisan crud:install
Generate a Basic CRUD
php artisan crud:generate Post title:string,body:text --stack=tailwind
Post) with Eloquent relationsPostController) with index, create, store, etc.resources/views/posts/--migration flag is used)Where to Look First
config/crud-generator.php (customize stacks, default paths, or field mappings).app/Http/Controllers/, app/Models/, and resources/views/ for auto-generated code.--stack=bootstrap|tailwind|livewire|api (default: tailwind).string, text, integer, boolean, date, datetime, and custom casts via --casts.Generating a CRUD with Relations
php artisan crud:generate User name:string,email:string --with-relations --relation=hasMany:Post
User model with hasMany relation to Post.posts migration.API-Only CRUD
php artisan crud:generate Product name:string,price:decimal:2 --stack=api
index, store, show, etc.StoreProductRequest).Livewire CRUD with Custom Logic
php artisan crud:generate Task title:string,status:boolean --stack=livewire
TaskComponent) with CRUD methods.app/Http/Livewire/TaskComponent.php (e.g., custom validation or business logic).Reusing Generators for Similar Models
--fields to reuse field definitions across models:
php artisan crud:generate Article title:string,body:text --fields=title:string,slug:string,published_at:datetime
app/Http/Requests/StorePostRequest) to add rules.// app/Providers/AuthServiceProvider.php
Gate::define('update-post', function ($user, $post) {
return $user->can('edit', $post);
});
public function __construct(private PostService $postService) {}
php artisan crud:test to generate feature tests for the CRUD (if supported in future versions).Migration Conflicts
crud:generate without --migration skips migration creation. Manually create it later or use --migration to avoid inconsistencies.php artisan crud:generate User name:string --migration --force
Stack Mismatches
--stack=bootstrap is used. This is intentional but may require manual adjustments.resources/views/livewire/.Relation Generation Quirks
morphTo, morphMany) are not auto-detected. Define them manually in the model after generation.--relation sparingly for complex relations; edit the model post-generation.Caching Issues
php artisan view:clear
php artisan config:clear
--force to overwrite or back up files first.config/crud-generator.php for custom paths or run:
php artisan crud:publish
to publish assets.Custom Stacks
php artisan vendor:publish --tag=crud-generator-stacks
resources/views/vendor/crud-generator/stacks/.Field Customization
resources/views/vendor/crud-generator/fields/{type}.blade.php.rich_text field type.Post-Generation Hooks
// app/Providers/AppServiceProvider.php
public function boot()
{
CrudGenerator::generated(function ($modelName) {
// Add custom logic, e.g., seed data or observers
});
}
API Resource Extensions
toArray() or toJson() methods in the generated model or resource class.php artisan crud:generate Post title:string,body:text --stack=tailwind
php artisan crud:generate Comment body:text,post_id:integer --stack=tailwind --relation=belongsTo:Post
dark: variants to classes.class StorePostRequest extends CrudFormRequest {
public function rules()
{
return array_merge(parent::rules(), [
'custom_field' => 'required|unique:posts',
]);
}
}
How can I help you explore Laravel packages today?