I see no need to store a computed value like that in your database. Just calculate it on the fly.
Count age and save it into table.
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 or to participate in this conversation.