adamnet's avatar

Passing data into anonymous component

I have an anonymous component named citizendata which is described below:

1 like
4 replies
vincent15000's avatar
<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 ?

vincent15000's avatar

Furthermore, if you are using anonymous components, you can pass the data like simple attributes and retrieve them as props.

@props([
	'passedData',
])

<div>
	{{ $passedData }}
</div>

And you can use the component like this.

<x-my-component passedData="some content" />
adamnet's avatar

I am creating an application for offering jobs to citizens who try to find a job. At first place the citizen must be regitered to the platform where he submits his name, surename, email and the date of birth. After that he may be interested to apply for a job he sees in the platform. A critical factor for being a candidate for the job will be his age. In the Citizen model there is only the dob field, age is something dynamic. After googling I think the proper solution will be to add a new attribute - an accessor - the attribute will be only iconic. There must be a function into the Citizen model which will be calculating the age of the citizen based on his date of birth. I wrote the function below (this is an accessor) into the Citizen model.

public function getageAttribute()
    {
    return Carbon::parse($this->dob)->diffInYears(Carbon::now());
    }

The code above didm't work. I will be happy if you can assist me on this :)

1 like

Please or to participate in this conversation.