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

dmytroshved's avatar

Is it possible to access a public property from one `FormObject` in another `FormObject`?

Hello everyone, I have Livewire 3 class RecipeWizard with 3 form objects:

class RecipeWizard extends Component

    use WithFileUploads;

    public Forms\RecipeForm $recipeForm;
    public Forms\IngredientsForm $ingredientsForm;
    public Forms\GuideForm $guideForm;

In RecipeForm I have a public property id:

class RecipeForm extends Form

    #[Locked]
    public int $id = 0;

Is it possible to get id from RecipeForm in GuideForm?:

class GuideForm extends Form

    $recipeForm->id; // ??


0 likes
2 replies
tisuchi's avatar
tisuchi
Best Answer
Level 70

@dmytro_shved Yes, you can inject the shared state via constructor or setter.

For example:

class GuideForm extends Form
{
    public int $recipeId = 0;

    public function setRecipeForm(RecipeForm $recipeForm): void
    {
        $this->recipeId = $recipeForm->id;
    }
}

Then in your RecipeWizard component:

public function mount()
{
    $this->guideForm->setRecipeForm($this->recipeForm);
}

Now you can access the $this->receipeId in the GuideForm.

1 like

Please or to participate in this conversation.