user8980183
user8980183

Reputation:

How to use/integrate jquery in laravel

Any idea how to deal with that? I mean do I need to install or manage some files in my project? I don't know how to manage that? Sorry I am just new in laravel

Upvotes: 1

Views: 7946

Answers (1)

Ahmed Nawaz Khan
Ahmed Nawaz Khan

Reputation: 1796

I will share two ways

a) In your view add this line in html head

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> and start writing your jquery code in script tag

b) The other way which i generally prefer is :

In Laravel 5.6 if u look at your package.json file jqueryis already present as npm dependency so

  1. create new laravel project laravel new my-project
  2. cd to my-project and run command npm install. This will install all dependencies included in package.json including jquery.
  3. now to compile down all these dependencies to one file in public/js/app.js add the line window.Jquery = require('jquery');to your resources/assets/js/app.js
  4. run command npm run dev

  5. add line <script src="{{ asset('js/app.js') }}"></script> to your welcome.blade.php

  6. Run the server and see the output you will be seeing the default laravel page with some links below Laravel heading
  7. add this code to your view now.

    <script>
        $(document).ready(function(){
        $(".links").hide();
    });
    

refresh page. you will not see the links below laravel now. which means jquery is up and working

Upvotes: 3

Related Questions