0

I have a javascript file in /public/js/ called myjavascript.js .

I want to include it in my site.

So I did this:

@extends('something')

    @section('scripts')
        <script src="/js/myjavascript.js"></script>
    @stop

@section('content')
...

This work in other project but not in this new one. What am I doing wrong?

2
  • 1
    Check your path is correct or not Commented Apr 20, 2017 at 10:03
  • provide full path of your .js file like src="<?php echo asset('/js/myjavascript.js'); ?>" Commented Apr 20, 2017 at 10:04

4 Answers 4

2

Try like this

<script src="{{ asset('/js/myjavascript.js') }}"></script>
Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

<script rel="text/javascript" src="{{ URL::asset('js/myjavascript.js') }}"></script>

3 Comments

or the shorter helper function asset()
or just <script src="{{ asset('/js/myjavascript.js') }}"></script> :)
That's what i suggested.
1

I think your code need to update like:

{!! Html::script('js/myjavascript.js') !!}

Hope this work for you!

Comments

1

<script src="{{ asset('/js/myjavascript.js') }}"></script> is perfect.

Check your APP_URL from .env file.

if your APP_URL=www.example.com then your source will be www.example.com/js/myjavascript.js

if your APP_URL=example.com/laravel then your source will be www.example.com/laravel/js/myjavascript.js
Check 'https://github.com/laravel/framework/blob/5.4/src/Illuminate/Foundation/helpers.php' for more about asset helper function

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.