ok, go with me on this for a moment. What happens in response to $med1->date_prescription_last_filled; ?
Carbon date not being set
Hi Everyone,
I am having a little trouble with the $dates feature of Eloquent. As you can see from the tinker output I have set the $dates property. When I call
$model->getAttribute('dateFieldName');
I get the correct value (an instance of Carbon) but when I call
$model->dateFieldName;
I get null. I have included some artisan tinker output below to illustrate my point.
3546 $ art tinker
Psy Shell v0.5.2 (PHP 5.5.27 — cli) by Justin Hileman
>>> $med1 = \MPC\Models\Medication::first();
=> MPC\Models\Medication {#703
id: 1,
user_id: 1,
name: "tramadol hydrochloride 50 MG Oral Capsule",
RXCUI: "836466",
preferredName: "Tramadol",
sizeOfEachUnit: null,
unitOfMeasurement: null,
howManyTakenPerTime: 2,
timesTakenPerTimePeriod: 4,
timePeriodTakenOver: "day",
unitsPerPrescription: 150,
datePrescriptionLastFilled: "2015-09-29 00:00:00",
reminder: 1,
remarks: "Prescription held at Doctor's as Tramadol is now a controlled drug",
created_at: "2015-10-14 22:30:33",
updated_at: "2015-10-14 22:30:33",
}
>>> $med1->getAttribute('datePrescriptionLastFilled');
=> Carbon\Carbon {#702
+"date": "2015-09-29 00:00:00.000000",
+"timezone_type": 3,
+"timezone": "UTC",
}
>>> $med1->getAttribute('datePrescriptionLastFilled')->addDays(25);
=> Carbon\Carbon {#706
+"date": "2015-10-24 00:00:00.000000",
+"timezone_type": 3,
+"timezone": "UTC",
}
>>> $med1->datePrescriptionLastFilled;
=> null
>>> $med1->created_at;
=> Carbon\Carbon {#690
+"date": "2015-10-14 22:30:33.000000",
+"timezone_type": 3,
+"timezone": "UTC",
}
>>> $med1->getDates();
=> [
"created_at",
"updated_at",
"datePrescriptionLastFilled",
"created_at",
"updated_at",
]
>>>
The field attribute is set as a timestamp in the migration file (it did begin as a date field and I couldn't get the 'Y-m-d' format to work so I switched to a timestamp format until I have the issue solved. Any help appreciated. Thanks in advance
Ok. I've solved this one. The problem was not only with the date attribute but every attribute of the model. The problem was that I declared the properties in the model. Without going through the source code I am not sure why but I noticed that some of the properties (the original ones) were not there but the newest ones worked as expected.
Please or to participate in this conversation.