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; // ??
@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.