Skip to content

[Feature] Nested Resource Generation #12

@devalade

Description

@devalade

Description

Generate CRUDs for nested resources (e.g., Posts → Comments, Projects → Tasks).

Proposed Syntax

# Generate Comment CRUD nested under Post
php artisan crudify:generate Comment \
  --fields="body:text" \
  --relationships="post:belongsTo:Post" \
  --nested=Post

Generated Components

  • Routes: /posts/{post}/comments, /posts/{post}/comments/{comment}
  • Controller: Scoped queries post->comments()->create()
  • Livewire: Parent-aware components
  • Breadcrumbs: Posts > {post title} > Comments
  • Navigation: Back to parent link

Example Routes

Route::get('/posts/{post}/comments', Comment\Index::class)->name('posts.comments.index');
Route::get('/posts/{post}/comments/create', Comment\Create::class)->name('posts.comments.create');
Route::get('/posts/{post}/comments/{comment}', Comment\Show::class)->name('posts.comments.show');

Example Livewire Create

class Create extends Component
{
    public Post $post;
    public string $body = '';
    
    public function mount(Post $post): void
    {
        $this->post = $post;
    }
    
    public function save(): void
    {
        $validated = $this->validate();
        $this->post->comments()->create($validated);
        
        $this->redirectRoute('posts.comments.index', $this->post);
    }
}

Key Considerations

  • Scoped authorization (can user access this post?)
  • Auto-fill parent relationship
  • Handle parent not found gracefully

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions