5

I'm using Laravel 5.1 and I watched Jeffrey's video about how to fix the facades issues. Now, Everything almost works perfect.

when I try code on my views for example:

<script type="text/javascript" src="assets/js/page.js"></script>

phpStorm marks this location as an error because he cannot resolve the location of the file because he's looking for the file Root/app/resources/views/layouts/assets/js/page.js which doesn't exists.

How can I fix this?

4 Answers 4

24

Step 1: Click on the File Menu

Step 2: Click on Settings, the following image should appear somewhat. (Yours may be different than mine)

Settings window

Step 3: In the search bar, type Directories, see the image:

Type Directories

Step 4: When you see the root of your project, click on the it and click on the Resource Root to mark it as the root of your project.

Step 5: Click on Apply

Step 6: Click on OK

And your query will be resolved. Hope this helps you out.

Sign up to request clarification or add additional context in comments.

2 Comments

In the step 4, when I select the folder holding the laravel project as root, the error does not disappear but when I select the public folder, the error does not appear anymore. Do you guys think that selecting the public folder as root can bring some issues or prevent some functionalities of laravel?
@Prince You should mark public as the root since that's the document root when serving the site. You should reference files within using /js/app.js rather than /resources/js/app.js in href attributes.
2

Change src="assets/js/page.js" to src="{{ asset('assets/js/page.js')}}"

The assets function is actually a function not a folder. I think it is referencing the expected in the public folder, but I'm still not 100% on that!

5 Comments

not quite what I asked, and there's no function assets, there's asset and it doesn't point to the public/assets/ folder.
My bad! You actually have an assets folder. Not a huge change. And there isn't you're correct it is asset changing now.
also yes I apparently misunderstood! glad it worked though!! :D
correct code is: <script type="text/javascript" src="{{ asset('assets/js/page.js') }}"></script> after src use = then "{{ }}"
@MostafaAsadi thank you. Idk how it has gone this long without that fix.
0

Use this code it will help you:

<script type="text/javascript" src="{{url('/assets/js/page.js')}}"></script>*

Comments

0

I'm using Laravel 11.x and this was the answer for me (since it uses Vite now). Basically, update your vite.config.js file to include a resolve block with the "@" alias:

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

export default defineConfig({
    plugins: ...whateverYouHaveHereAlready,
    resolve: {
        alias: {
            '@': path.resolve(__dirname, 'resources/js'), // Adjust to your actual path
        },
    },
})

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.