laraveldatelaravel-5vue.jsvuejs2

Convert date format in vue js with laravel


I'm using verta library to convert gregorian dates to hijri date in laravel https://github.com/hekmatinasser/verta

in simple mode (.blade.php files) I'm using code like this:

{{ Verta($category->created_at)->format('%d %B %Y') }}
for converting {{created_at}}

but in Vue js I can't access to this format an I have

{{category.created_at}}

how can I convert the vue js dates with this method?


Solution

  • You can use a mutator on your model to parse the date before returning it.

    public function getCreatedAtAttribute($value)
    {
        return Verta($value)->format('%d %B %Y');
    }
    

    This should be defined on your Category Model

    {{category.created_at}}
    

    Will then contain the already parsed date