vendredi 9 décembre 2016

better way to call a function from view in laravel

I have a function that returns a difference of two dates
Since the dates are generated from database there can be multiple records that needs to call this function.

function dateDifference($date_1 , $date_2 , $differenceFormat = '%y Year %m Month' )
   {
    $datetime1 = date_create($date_1);
    $datetime2 = date_create($date_2);

    $interval = date_diff($datetime1, $datetime2);

    return $interval->format($differenceFormat);
   }

now what i have to do is i have to call this function from view since there can be multiple date differences in a page. And It is not very professional to keep the logic in the view.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire