mr.incognito/crudify
Laravel CRUD generator for API or web apps. One Artisan command scaffolds models, migrations, controllers, form requests, API resources, routes, and optional Blade views. Supports validation rules, nullable fields, foreign keys/constraints, defaults, excludes, and delete:crud cleanup.
To begin using mr.incognito/crudify, install the package via Composer:
composer require mr.incognito/crudify
First Use Case: Generate a basic API CRUD for a User model with two fields (name and email):
php artisan make:crud User --fields="name:string|max:255;email:string~|unique:users"
This creates:
app/Models/User.php)database/migrations/..._create_users_table.php)app/Http/Controllers/Api/UserController.php)app/Http/Requests/UserRequest.php)app/Http/Resources/UserResource.php)routes/api.phpWhere to Look First:
app/Http/Controllers/Api/ or app/Http/Controllers/Web/ for generated controllers.resources/views/ (for web CRUDs) to customize Blade templates.Pattern: Use for internal APIs, admin panels, or third-party integrations.
php artisan make:crud Department --fields="name:string|max:255;created_by:foreign~|constrained:users" --type=api
Integration Tips:
DepartmentController for custom logic (e.g., store(), update()).
public function store(DepartmentRequest $request) {
$validated = $request->validated();
$validated['created_by'] = auth()->id(); // Auto-set creator
return parent::store($request);
}
DepartmentRequest:
public function rules() {
return [
'name' => ['required', 'max:255', 'regex:/^[A-Za-z\s]+$/'],
];
}
DepartmentResource to shape responses:
public function toArray($request) {
return [
'id' => $this->id,
'name' => $this->name,
'created_at' => $this->created_at->format('Y-m-d'),
];
}
Pattern: Use for admin dashboards or setup wizards.
php artisan make:crud Article --fields="title:string;content:text" --type=web
Integration Tips:
resources/views/articles/ (e.g., add Alpine.js for interactivity).ArticleRequest for custom authorization:
public function authorize() {
return auth()->user()->can('manage-articles');
}
ArticleController:
public function update(ArticleRequest $request, Article $article) {
if ($article->user_id !== auth()->id()) {
abort(403);
}
return parent::update($request, $article);
}
Pattern: Skip files you don’t need (e.g., exclude migrations if using an existing DB).
php artisan make:crud Settings --fields="key:string;value:text" --type=api --exclude=migration,model
Use Case: Rapidly add a controller/resource for an existing table.
Pattern: Define relationships with constraints.
php artisan make:crud Order --fields="user_id:foreign|constrained:users|onDelete:cascade;product_id:foreign|constrained:products"
Post-Generation:
public function user() {
return $this->belongsTo(User::class);
}
Pattern: Use ~ for nullable fields and default: for defaults.
php artisan make:crud Product --fields="name:string;price:decimal~|default:0.00;is_active:boolean~|default:false"
Route Conflicts:
/api/departments) may clash with existing routes. Fix: Manually adjust routes/api.php or use route model binding in controllers.--type=web for web routes to avoid API conflicts.Foreign Key Mismatches:
php artisan delete:crud to clean up failed attempts.Blade Template Overrides:
resources/views/. Gotcha: Forgetting to clear the view cache (php artisan view:clear) after changes.@extends and @section in custom templates to preserve layout structure.Validation Rule Conflicts:
FormRequest may override generated rules. Fix: Merge rules explicitly:
public function rules() {
return array_merge(parent::rules(), [
'custom_field' => 'required|custom_rule',
]);
}
Migration Timestamps:
created_at/updated_at. Gotcha: Adding these to an existing table may cause errors if columns already exist.--exclude=migration and write a custom migration.API Resource Caching:
AppServiceProvider or use Resource::withoutWrapping().app/Http/Requests/).--verbose to see generation steps:
php artisan make:crud User --verbose
php artisan make:request TestRequest
Then manually validate:
$request = new TestRequest(['field' => 'invalid']);
$validator = Validator::make($request->all(), $request->rules());
Custom Templates:
resources/views/vendor/crudify/ to your project’s resources/views/ directory.@include to reuse partials.Rector for Refactoring:
composer rector to upgrade generated code to newer Laravel versions.Pest Tests:
tests/Feature/CrudTest.php:
public function test_custom_logic() {
$response = $this->post('/api/users', ['name' => 'Test']);
$response->assertStatus(201);
}
Dynamic Field Generation:
--type=api (defaults to API). Always specify --type=web for web CRUDs to avoid confusion.--exclude=model,migration).~ for nullable fields and | for rules are correctly placed:
--fields="email:string~|email:required|unique:users"
--exclude=migration when deleting CRUDs to preserve DB history.User, Role, Permission) for RBAC systems.CRUD_GENERATION.md file to track excluded files or customizations per model.public function toSearchableArray($search) {
return ['name' => $this->name];
}
How can I help you explore Laravel packages today?