Eliya Cohen
Eliya Cohen

Reputation: 11458

Laravel and phpStorm integration - "cannot resolve directory"

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?

Upvotes: 5

Views: 5599

Answers (4)

Brandon Aaskov
Brandon Aaskov

Reputation: 352

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
        },
    },
})

Upvotes: 0

Merve Bozkurt
Merve Bozkurt

Reputation: 39

Use this code it will help you:

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

Upvotes: 0

Cayce K
Cayce K

Reputation: 2338

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!

Upvotes: 2

Saiyan Prince
Saiyan Prince

Reputation: 4020

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.

Upvotes: 24

Related Questions