- How do I install and set up mr.incognito/crudify in a Laravel 9 project?
- Run `composer require mr.incognito/crudify` in your project root. No additional configuration is needed—just use the `make:crud` Artisan command. Ensure your Laravel version is 8/9/10 and PHP 8.0+ for compatibility. The package integrates seamlessly with Laravel’s conventions without requiring service providers or publishers.
- Can this package generate API-only CRUD without Blade views?
- Yes, use the `--type=api` flag with `php artisan make:crud`. This skips Blade view generation and creates only models, migrations, controllers, and API resources. It’s ideal for headless Laravel APIs or SPAs. Example: `php artisan make:crud Post --fields='title:string' --type=api`.
- What validation rules does the package support, and how do I add custom ones?
- The package supports Laravel’s built-in validation rules (e.g., `string`, `integer`, `max:255`, `required`) via the `--fields` parameter. For custom rules, append them after the type, like `field:custom_rule`. However, complex custom logic may require manual post-generation edits to the generated `FormRequest` class. Example: `--fields='email:string|email|unique:users'`.
- Does mr.incognito/crudify support foreign keys with cascading deletes?
- Yes, specify foreign keys with `|constrained:table` and cascade rules with `|onDelete:cascade`. Example: `--fields='user_id:foreign|constrained:users|onDelete:cascade'`. The package generates the appropriate `$table->foreign()` syntax in migrations and ensures referential integrity. Nullable foreign keys use the `~` suffix (e.g., `user_id:foreign~`).
- Will generated Blade views work with Tailwind CSS or custom styling?
- The generated Blade views are basic and unbranded, so they’ll work with Tailwind or any CSS framework if you include your stylesheet. For custom styling, override the generated views in `resources/views/vendor/crudify/` or manually edit the auto-generated files. The package doesn’t enforce a specific UI library, so integration is flexible.
- Is there a way to exclude certain files (e.g., skip generating the model or migration)?
- Yes, use the `--exclude` flag followed by a comma-separated list of files to skip. For example, `php artisan make:crud Product --exclude=migration,controller` will omit the migration and controller files. Supported exclusions include `model`, `migration`, `controller`, `request`, `resource`, and `views`.
- How do I clean up generated CRUD files if I no longer need them?
- Use the `delete:crud` Artisan command to remove all generated files for a specific CRUD. Run `php artisan delete:crud ModelName` (replace `ModelName` with your model class name). This deletes models, migrations, controllers, requests, resources, and Blade views (if applicable). Always back up your project before running cleanup commands.
- Does this package work with Laravel Sanctum or Passport for authentication?
- No, the package doesn’t integrate with Sanctum or Passport out of the box. Generated controllers use Laravel’s default auth middleware (e.g., `auth:api`). For Sanctum/Passport, manually add the middleware to the generated controller or use a post-generation script (e.g., Rector) to inject the auth logic. Example: Add `'middleware' => ['auth:sanctum'],` to the controller.
- Are there alternatives to mr.incognito/crudify for more customizable CRUD generation?
- Yes, consider Laravel Nova (paid, feature-rich) or Filament (free/paid, modern UI) for highly customizable admin panels. For API-only projects, tools like Laravel API Resources or manual scaffolding with Laravel Jetstream may offer more control. If you need Livewire/Inertia.js support, this package isn’t a fit—opt for custom scaffolding or packages like Livewire CRUD generators.
- How do I handle complex validation logic that isn’t supported by the package?
- For complex validation, manually edit the generated `FormRequest` class after running the `make:crud` command. Override the `rules()` method to add custom logic, such as dynamic rules based on user roles or database checks. Example: Add `public function rules() { return array_merge(parent::rules(), ['custom_field' => 'custom_rule']); }` to the request class.