Installation:
Run composer require mrdebug/crudgen --dev and publish assets with:
php artisan vendor:publish --provider="Mrdebug\Crudgen\CrudgenServiceProvider"
This sets up config, stubs, and default views.
Quick CRUD Generation:
Generate a basic CRUD for a Post model with:
php artisan crudgen:create Post --fields="title:string,content:text" --hasMany=Comment --belongsToMany=Tag
This auto-creates:
PostController)Post.php) with relationshipsposts_table)StorePostRequest, UpdatePostRequest)--api flag is used)First Use Case:
Test the CRUD by visiting /posts (web) or /api/posts (API). The package handles:
Comment, Tag models are stubbed)Model-Driven Generation:
php artisan crudgen:create User --fields="name:string,email:string:unique" --belongsTo=Role --morphMany=Activity
belongsTo, hasMany, morphMany).required|email for email).View Customization:
resources/views/vendor/crudgen/{model}/.resources/views/{model}/ and modifying.@include('crudgen::partials.form-field', ['field' => 'content']) for reusable field rendering.API Integration:
--api:
php artisan crudgen:create Product --fields="name:string,price:decimal:8,2" --api
GET /api/products, POST /api/products, etc.with()).Relationship Handling:
/posts/{post}/comments).morphTo/morphMany (e.g., for activity logs).Validation and Authorization:
Store{Model}Request, Update{Model}Request) include default rules.app/Http/Requests:
public function rules()
{
return array_merge(parent::rules(), ['custom_field' => 'required']);
}
Seeding:
--seed to generate a seeder for the model:
php artisan crudgen:create Category --fields="name:string" --seed
config/crudgen.php).php artisan crudgen:install to set up config and views after installation.config/crudgen.php under custom_fields:
'custom_fields' => [
'rich_text' => ['type' => 'textarea', 'attributes' => ['rows' => 5]],
],
php artisan vendor:publish --tag=crudgen-lang
resources/lang/{locale}/crudgen.php.CrudgenTestCase (included) to test generated CRUDs:
use Mrdebug\Crudgen\Testing\CrudgenTestCase;
class PostCrudTest extends CrudgenTestCase
{
public function testCreatePost()
{
$this->createCrud('Post');
$this->post('/posts', ['title' => 'Test', 'content' => 'Body']);
$this->assertDatabaseHas('posts', ['title' => 'Test']);
}
}
Migration Conflicts:
--force:
php artisan crudgen:create Post --fields="title:string" --force
--no-migration to skip migration creation if needed.Relationship Errors:
php artisan crudgen:create Comment --fields="content:text" --belongsTo=Post
Run this after generating the Post CRUD.config/crudgen.php for relationships validation.View Overrides:
php artisan view:clear
@extends('crudgen::layouts.app') in custom views to inherit the base layout.API Route Conflicts:
api/. If conflicts arise, rename the model or adjust routes in routes/api.php.php artisan route:list to check for duplicates.Validation Rule Mismatches:
Update{Model}Request may conflict with auto-generated ones.public function rules()
{
return array_merge(parent::rules(), ['price' => 'min:0']);
}
Polymorphic Relationships:
morphs table exists (e.g., activities). The package auto-creates it for morphMany.morphMap in AppServiceProvider:
public function boot()
{
\Mrdebug\Crudgen\Crudgen::morphMap([
'post' => \App\Models\Post::class,
'comment' => \App\Models\Comment::class,
]);
}
Configuration Overrides:
config/crudgen.php. Common overrides:
'default_namespace' => 'App\\Http\\Controllers\\Admin',
'use_api_resources' => true,
'form_request_namespace' => 'App\\Http\\Requests\\Admin',
Custom Field Types:
Mrdebug\Crudgen\Field\FieldInterface:
namespace App\Crudgen\Fields;
use Mrdebug\Crudgen\Field\FieldInterface;
class RichTextField implements FieldInterface
{
public function render()
{
return '<trix-editor>' . $this->value . '</trix-editor>';
}
}
config/crudgen.php:
'custom_fields' => [
'rich_text' => \App\Crudgen\Fields\RichTextField::class,
],
Custom Actions:
namespace App\Http\Controllers;
use Mrdebug\Crudgen\CrudController;
class PostController extends CrudController
{
public function publish($id)
{
$post = $this->model->findOrFail($id);
$post->update(['status' => 'published']);
return back()->with('success', 'Post published!');
}
}
routes/web.php:
Route::put('/posts/{id}/publish', [PostController::class, 'publish'])->name('posts.publish');
Custom Views:
php artisan vendor:publish --tag=crudgen-views
resources/views/vendor/crudgen/{model}/index.blade.php.Custom API Resources:
namespace App\Http\Resources;
use Mrdebug\Crudgen\CrudResource;
class PostResource extends CrudResource
How can I help you explore Laravel packages today?