How to add JQuery in Laravel blade view template

Posted on

This is an article which is written to show how to add JQuery in a web-based application based powered by Laravel framework. Laravel framework which is actually using PHP as the base of its programming language. Another thing which is considered as an important thing included in a Laravel framework powering the web-based application is the usage of JQuery library. Whenever the web-based application needs a Javascript for client-side scripting, JQuery is one of the alternative available to provide Javascript library to enrich the web-based application itself. So, in this article, there are few steps need to be taken so that JQuery can be available to be used in a Laravel blade view template file :

1. Download the JQuery file library from the official site of JQuery in this link. To be more specific, it can be downloaded from the JQuery download page in this link. There are lots of version available to be downloaded from the download page. Just choose the appropriate version or to play it safe just take the last or the newest version available.

2. After downloading the file, place it in the specific folder or directory meant for the importing file and in the case of web-based on Laravel framework it is located in public/js. So, if it is described in the folder structure, it can be shown as follows :

root-folder-of-web-application-based-laravel-framework
|----public
       |-----js
              |-----jquery-3.2.1.min.js
  1. After placing the JQuery file on the right place, declared the import line of code in the main blade view file template as shown below :
<script src="{{ URL::asset('js/jquery-3.2.1.min.js') }}"></script>

The important thing which is needed to be focused on is the ‘js’ folder which is located in the public folder. The rest full path folder is actually represented by the following : {{ URL::asset … }}. It will be parsed and translated as /root-folder/public. So, the rest is just adding the folder which is used to contain the JQuery file and in this context is the ‘js’ folder.

One thought on “How to add JQuery in Laravel blade view template

Leave a Reply