dimanche 24 mars 2019

Laravel Blade Directive Check If Valid Date Conditional Failing

In my AppServiceProvider I have a custom blade directive I've set up to consistently format dates throughout the UI of this app. I want it to check that it's a valid date before trying to format it though.

Why is it that this does not work:

Blade::directive('dateui', function ($date) {
    if ($date instanceof \DateTime || $date instanceof \Illuminate\Support\Carbon) {
        return "<?php echo ($date)->format(config('rentallink.uiDateFormat')); ?>";
    }
});

Yet when I put the conditionals into the evaluated php it works.

Blade::directive('datetimeui', function ($date) {
    return "<?php
        if ($date instanceof \DateTime || $date instanceof \Illuminate\Support\Carbon) {
            echo ($date)->format(config('rentallink.uiDateFormat'));
        }
    ?>";
});

If I dump out $date, it is a carbon object so I don't understand how a basic conditional isn't working. I'm assum

Yes I'm clearing the compiled views in between requests:

php artisan view:clear



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire