PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, December 30, 2021

[FIXED] Convert date format in vue js with laravel

 December 30, 2021     date, laravel, laravel-5, vue.js, vuejs2     No comments   

Issue

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



Answered By - Frnak
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing