Thursday, March 9, 2017

Cannot set Carbon variable in Laravel

I want to set the value of an item to hours and minutes like this:

    if($item->created_at->gte($begin_date) && $item->created_at->lte($end_date))
    {
        $item->created_at = $item->created_at->format('H:m');
        $sorted_items[] = $item;
    }
}

When I use dd($item->created_at->format('H:m')) it shows the hour and minute correctly, however when I try to set $item->created_at to the hour and minute it throws me this error:

InvalidArgumentException in Carbon.php line 582:
Unexpected data found.
Data missing



via prgrm

Advertisement