© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
9 replies
Raziul Islam

Nesting form fields depending on relationships

I am not sure it is possible or not but I want to give it a try.
Let me give you some idea on my project:

Models:
// Product
class Product extends Model
{
    public function brand(): BelongsTo
    {
        return $this->belongsTo(Brand::class);
    }

    public function specifications(): BelongsToMany
    {
        return $this->belongsToMany(Specification::class, 'product_specifications', 'product_id', 'specification_id');
    }
}


// Specification
class Specification extends Model
{
    public function category(): BelongsTo
    {
        return $this->belongsTo(SpecCategory::class, 'spec_category_id');
    }

    public function type(): BelongsTo
    {
        return $this->belongsTo(SpecType::class, 'spec_type_id');
    }

    public function products(): BelongsToMany
    {
        return $this->belongsToMany(Product::class);
    }
}

// SpecCategory
class SpecCategory extends Model
{
    public function types(): HasMany
    {
        return $this->hasMany(SpecType::class, 'spec_category_id');
    }

    public function specifications(): HasMany
    {
        return $this->hasMany(Specification::class, 'spec_category_id');
    }
}


// SpecType
class SpecType extends Model
{
    public function category(): BelongsTo
    {
        return $this->belongsTo(SpecCategory::class, 'spec_category_id');
    }

    public function specifications(): HasMany
    {
        return $this->hasMany(Specification::class, 'spec_type_id');
    }
}
// Product
class Product extends Model
{
    public function brand(): BelongsTo
    {
        return $this->belongsTo(Brand::class);
    }

    public function specifications(): BelongsToMany
    {
        return $this->belongsToMany(Specification::class, 'product_specifications', 'product_id', 'specification_id');
    }
}


// Specification
class Specification extends Model
{
    public function category(): BelongsTo
    {
        return $this->belongsTo(SpecCategory::class, 'spec_category_id');
    }

    public function type(): BelongsTo
    {
        return $this->belongsTo(SpecType::class, 'spec_type_id');
    }

    public function products(): BelongsToMany
    {
        return $this->belongsToMany(Product::class);
    }
}

// SpecCategory
class SpecCategory extends Model
{
    public function types(): HasMany
    {
        return $this->hasMany(SpecType::class, 'spec_category_id');
    }

    public function specifications(): HasMany
    {
        return $this->hasMany(Specification::class, 'spec_category_id');
    }
}


// SpecType
class SpecType extends Model
{
    public function category(): BelongsTo
    {
        return $this->belongsTo(SpecCategory::class, 'spec_category_id');
    }

    public function specifications(): HasMany
    {
        return $this->hasMany(Specification::class, 'spec_type_id');
    }
}


So each Specification has SpecType and SpecCategory.
example:
example:
specification: 16GB, type: RAM, category: Memory

Now the product has specification like: Samsung S24 Ultra has 16GB ram and I want to structure the form in that way.
Screenshot_2024-04-18_014621.png
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Depending fields
FilamentFFilament / ❓┊help
11mo ago
How do form fields with relationships work?
FilamentFFilament / ❓┊help
2y ago
Form relationships
FilamentFFilament / ❓┊help
2y ago