How to Install and Use Moment JS in Laravel?

About Us:

We are from free coder. We are a group of web developers who are passionate about web development. You can learn from us php, laravel, node js, vue js, react js and many other topic on web developement.
we are very happy to help you.
free coder

Today what you are going to learn:

This tutorial will provide lesson of how to use moment js in laravel. step by step explain how to install moment in laravel vue. we will help you to give lesson of install moment in laravel. This article will give you simple lesson of use moment js in laravel.

In this lesson i will show you step by step how to install moment in laravel mix. i will give you two lesson of installing moment in laravel. one will be using npm command using laravel mix and another lesson will using cdn js.

You can easily use moment in laravel 6, laravel 7 and laravel 8 version. so let's see bellow step be step process.

1) Install Using Npm

first, we will install laravel fresh version. so let's run bellow command:

composer create-project --prefer-dist laravel/laravel blog

Now, we need to install npm in our new laravel application. so let's simply run bellow command. this command will create "mode_modules" folder in your root directory and store all npm module there.

npm install

After that we need to install font awesome library using bellow npm command. so let's run bellow command:

npm install moment

After install successfully, we can use in our app.js file. so let's import as bellow:

resources/js/app.js

require('./bootstrap');

var moment = require('moment');

console.log(moment().format());

Now we are ready to run npm dev command, so let's run bellow command:

npm run dev

Hello Brother, we will use generated app.css file in our blade file as bellow:

resources/views/welcome.blade.php

<!DOCTYPE html>

<html>

<head>

<title></title>

<link type="text/css" rel="stylesheet" href="{{ mix('css/app.css') }}">

<script type="text/javascript" src="{{ mix('js/app.js') }}"></script>

</head>

<body>

<h1>How to use moment js in Laravel? - ItSolutionStuff.com</h1>

</body>

</html>

Now you can run your application and see on home page. You will get output as bellow:

2020-06-10T19:58:17+05:30

2) Install Using CDNJS

here, we will use cdn js file for adding moment js, so let see bellow file code:

resources/views/welcome.blade.php

<!DOCTYPE html>

<html>

<head>

<title></title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.26.0/moment.min.js"></script>

</head>

<body>

<h1>How to use moment js in Laravel? - ItSolutionStuff.com</h1>

<script type="text/javascript">

var cTime = moment().format();

console.log(cTime);

</script>

</body>

</html>

thank you very much for following up with me.

Tags

Recent Posts

Related Posts