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: 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.
No description
8 Replies
Raziul Islam
Raziul IslamOP8mo ago
While creating/adding new product the user will just select the specification values from the options and for that I need to organize the form to make it user friendly.
Raziul Islam
Raziul IslamOP8mo ago
Here Memory is SpecCategory, RAM and Storage are SpecType and the options (1GB, 2GB, ...) are Specifications
No description
Raziul Islam
Raziul IslamOP8mo ago
I was hoping to get feedback from others 😔
Povilas K
Povilas K8mo ago
I think what you're talking about is called Custom Fields, I have a video about it: https://youtu.be/njkY4w8UqNY?si=jcPGC2kmw2QY3wdd
Filament Daily
YouTube
Filament Form: Custom Fields with Unique Validation
Showcasing another Filament example with adding custom fields to the customer form. Source: https://filamentexamples.com/project/form-custom-fields
Raziul Islam
Raziul IslamOP8mo ago
Thanks but that doesn't fit my need.
Raziul Islam
Raziul IslamOP8mo ago
This is what I did.
No description
Raziul Islam
Raziul IslamOP8mo ago
No description
Raziul Islam
Raziul IslamOP8mo ago
Only down side is that I needed to add a json column (specs) to the products table.
Want results from more Discord servers?
Add your server