laravel-mix: Wrong laravel mix rewrite url path when place project in subfolder
I did install my laravel project on http://localhost/laravel and I run this project in browser at http://localhost/laravel/public
current url path on compiled scss files is font/vendor/something, can laravel mix replace url path with relative path base on compiled scss like ../fonts/vendor/something?
I knew if I run my project with php artisan serve it won’t be a problem, what if I install my project in subfolder?

About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19
I solved this problem using this:
{{ url(mix('/all.min.css')) }}I added
'mix_url' => env('APP_URL', 'http://localhost'),on config/app.php and also set the APP_URL on env as per subfolder to solve this.For me, it also worked using asset. This is great if your project is inside sub folders.
You can actually see that from the mix manifest, it is attached to the root,
/js/yourfile.js.Adding
asset()will post-fix those/js/yourfile.jsto proper current project folder.Without asset:
http://localhost/js/yourfile.jsWith asset:http://localhost/your/nested/subfolders/public/js/yourfile.js@fzldn try
mix.setResourceRoot('/laravel/public/');@ramakrishnamundru it works fine, thanks
mix.setResourceRoot('../');This does not work for me. Assets are output without my folder prefix.
Hello brothers. i’m having same issue. when click the linked file it redirecting to wrong path and skip 2 dir. please look up my file structure http://prntscr.com/pcgf8o http://prntscr.com/pcgfpz http://prntscr.com/pcgfwj http://prntscr.com/pcgg3w when click its redirecting to http://localhost/css/app.css?id=577fcf1b727f3ba9d298 its shoult to redirect to http://localhost/anan/public/css/app.css?id=577fcf1b727f3ba9d298
i’m suffering this problem for many days please someone help me
@MGParisi I put the code inside my .blade.php, as like any other html syntax
<script src="{{ asset(mix('/js/yourfile.js')) }}"></script>For your SCSS, it is being compiled into CSS. It means that your image is relative to that compiled folder location.
Eg, below might be your structure project of public:
/public |-- /css |----/app.css |–/assets |----/images |------/bg-page-heading.jpg
So, to retrieve your
bg-page-heading.jpg, you would adjust your SCSS as follow:background: url(../assets/images/bg-page-heading.jpg);Notice the
..to state that, “Hey, go back one folder, and then to assets, images and finally my image that I want”