<x- citizendata :citizen="$citizen"/>
When you pass the citizen model to your component, you can access the years variable from inside the component.
$citizen->years
What are you really trying to do ?
I have an anonymous component named citizendata which is described below:
<div class="col-sm">
<div class="form-floating">
<input type="text" class="form-control" id="firstname" name="firstname" value="{{ old('firstname', $citizen->firstname ?? '') }}" >
@error('firstname')
<span class="text-danger">{{$message}}</span>
@enderror
<label for="firstname"><strong>First Name</strong></label>
</div>
</div>
<div class="col-sm">
<div class="form-floating">
<input type="text" class="form-control" id="surname" name="surname" value="{{ old('surname', $citizen->surname ?? '') }}" >
@error('surname')
<span class="text-danger">{{$message}}</span>
@enderror
<label for="surname"><strong>First Surname</strong></label>
</div>
</div>
<div class="col-sm">
<div class="form-floating">
<input type="text" class="form-control" id="age" name="age" value="{{ old('age', $years ?? '') }}" readonly>
@error('age')
<span class="text-danger">{{$message}}</span>
@enderror
<label for="age"><strong>Age</strong></label>
</div>
</div>
</div>```
I inject this component in the form this way:
```<x- citizendata :citizen="$citizen"/>```
My question is how can I pass the age of the citizen in the citizen's form. The age is a dynamic value calculated in the controller
```$years = Carbon::parse($birthdate)->age;```
How can I pass the $years value into the form?
Please or to participate in this conversation.