Blade::directive('test', function($arguments) {
list($current_date, $date) = explode(',',str_replace(['(',')',' ', "'"], '', $arguments));
return "<?php echo($date->diffInDays($current_date));
});
This should simply return the difference between the 2 given dates
@set($current_date, Carbon::now())
This is how i set $current_date using another Blade directive
@test($current_date, $complaint->created_at)
This is how i call the test directive
Im getting the following error
Trying to get property 'diffInDays' of non-object
What i dont understand is: if if put the following code in my view, it gives me the difference, and its simply the same as the blade directive above
@php
echo($complaint->created_at->diffInDays($current_date))
@endphp
I even put the dates in the protected_dates field in my Complaint Model.. but i dont think thats the problem here.
thanks in advance!