philipbaginski
5 months ago
867
11
Nova

Count age and save it into table.

Posted 5 months ago by philipbaginski

Hi everyone! Next problem :-) :

In the table A I have column DOB with date: 2020-05-11. Base on this column I have to count age. As long as the age from 01.01 to 31.12 is the same I use code:

public function getAgeAttribute() { return $this->dob->startOfYear()->diffInYears(); }

And it works. Age is displayed. But I have to save this age in another table related to table A, lets say B.

There is a hidden field able to make this work, and in resource B I did a set up of request:

public function getAgeAttribute() { return $this->resourceA->dob->startOfYear()->diffInYears(); }

Hidden::make('Sample', 'sample_age')->default(function ($request) { return $request->getAgeAttribute; }),

,but it does not work.

Any idea?

Please sign in or create an account to participate in this conversation.