How to get the remaining time up to the date of consumption ..
{{$item->created_at->toDateString()->diffInDays($item->expired)}}
{{$item->created_at->toDateString() - $item->expired}}
How to get the remaining time up to the date of consumption ..
{{$item->created_at->toDateString()->diffInDays($item->expired)}}
{{$item->created_at->toDateString() - $item->expired}}
You are trying to call a function on a string.
See:
$item
Instance of \Illuminate\Database\Eloquent\Model
$item->created_at
Instance of \Carbon\Carbon
$item->created_at->toDateString()
string
$item->created_at->toDateString()->diffInDays()
FatalThrowableError Call
to a member function diffInDays() on string
Try:
{{ $item->created_at->diffInDays($item->expired) }}
After comment: Your expired attribute is a string and not a date: Tell Eloquent to mutate it as a date:
class Item {
protected $dates = ['expired'];
}