Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jcc5018's avatar

Filament dependent dropdowns not displaying the old record

I am trying to get a dependent dropdown to display correctly for my article type categories.

This set up current displays the correct child category for the chosen parent category, and saves a record in the database, but when I refresh, that record is not populated, and updating creates a new record instead of updating the existing category.

An article can only have one category, but may have many tags. But both are stored in the tags table. Only the selected "child category" is stored, so if a record is present in the taggables table, then the parent category has to be determined by the parent_id of the taggable record when populating existing records.


    public function categories()
    {
        return $this->morphToMany(Tag::class, 'taggable')->where('tag_type', 12)
                    ->withTimestamps();
    }

    public function tags()
    {
        return $this->morphToMany(Tag::class, 'taggable')->where('tag_type', 20)
                    ->withTimestamps();
    }

I currently have 3 records in the taggables table for my 3 test trying to make this work. When there should only be one that is updating

Sample set up: parent category -How to (id 1)

--child categories [ instructions [id 2, parent_id=1], rules [id 3, parent_id=1], tips [id 4, parent_id=1]]

so if an article is associated with TIPS, tag_id=>4 will be in the taggables table in which the parent category of "how to" should be derived.

But neither parent or child categories are being selected when I refresh or return to edit the Article.

0 likes
2 replies
LaryAI's avatar
Level 58

To address the issue of dependent dropdowns not displaying the old record correctly, you need to ensure that the default values for both the parent and child categories are set correctly when the form is loaded. Additionally, you need to make sure that the relationships are properly defined and that the form fields are correctly populated with the existing data.

Here's a revised version of your code with some adjustments to ensure that the old records are displayed correctly:

Additionally, ensure that your categories relationship is correctly defined in your model:

public function categories()
{
    return $this->morphToMany(Tag::class, 'taggable')
                ->where('tag_type', 12)
                ->withTimestamps();
}

And make sure that the Tag model has the necessary relationships to get the parent category:

class Tag extends Model
{
    public function parent()
    {
        return $this->belongsTo(Tag::class, 'parent_id');
    }

    public function children()
    {
        return $this->hasMany(Tag::class, 'parent_id');
    }
}

By ensuring that the default values are correctly set and that the relationships are properly defined, the dependent dropdowns should display the old records correctly when you refresh or return to edit the article.

Please or to participate in this conversation.