I have a carbon instance in the variable $startTime:
Carbon @1574958600 {#781 ▼
date: 2019-11-28 16:30:00.0 UTC (+00:00)
}
I have in the column "duration" of table OFFERS in the DB (time format) 30 minutes in this format: 00:30:00
Now I want to add those 30 minutes to the $startTime.
I get the data from DB:
$offer = Offer::select('duration')->where('id', $offerId)->first();
It works correctly. and I try to store that value into a variable $duration
$duration = $offer->duration;
and I get this error:
Unexpected data found. Unexpected data found. Data missing
I supposed I have to format this stringto Carbon, so I did:
$duration = Appointment::setDateAttribute($offer->duration);
I got again the error: Unexpected data found. Unexpected data found. Data missing
And now I am lost.
I just wanted to make a simple addition:
$endTime = $startTime + $offer->duration;
But I am stock with this since hours.
Any idea what am I doing wrong?
Another though was:
Is it possible to make this operation in a query and add the 30 minutes 'on the fligh' while I get the duration? Somehow pass the variable $startTime to the query and do something like:
$duration= Offer::where('id', $offerId)
->whereHas('duration', function ($query) {
$query->get('duration', 'and add the $startTime variable here'); // <- make the calculation here
})
->select('duration as duration', 'endTime') // endTime would be the calculated data
->first();
Either one or another solution. But at the moment I am stock with this