Skip to content

[Feature] Many-to-Many Relationship Support #2

Description

@devalade

Description

Currently belongsToMany relationships are added to the model, but migration pivot tables and attach/detach UI are missing.

Current Behavior

php artisan crudify:generate Post \
  --relationships="tags:belongsToMany:Tag"

Only generates model method - no pivot table, no UI for attaching tags.

Expected Behavior

  • Generate pivot table migration (post_tag)
  • Generate Tag model if it doesn't exist
  • Livewire Create/Edit: Add multi-select checkbox/tag input for attaching
  • Index: Show related tags as badges
  • Form request: Validate array of IDs with Rule::exists

Example UI

<div class="space-y-2">
    <label>Tags</label>
    <div class="flex flex-wrap gap-2">
        @foreach($allTags as $tag)
            <label class="inline-flex items-center">
                <input type="checkbox" wire:model="selectedTags" value="{{ $tag->id }}">
                <span>{{ $tag->name }}</span>
            </label>
        @endforeach
    </div>
</div>

API

$post->tags()->sync($this->selectedTags);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions