简体   繁体   中英

asset('assets') return to wrong directory after using prefix in laravel

This is the line I load my assets:

<script src="{{ asset('assets') }}/js/vendors/jquery-3.2.1.min.js"></script>

And here code from web.php for route settings:

Route::resource('masuk', 'Backend\ParkirInController');

It works fine with this code, but when I using a prefix like here:

Route::group(['prefix'=>'parkir'], function (){
   Route::resource('masuk', 'Backend\ParkirInController');
});

The assets are not loaded and show an error like

require.min.js:5 GET http://localhost:8000/parkir/assets/js/vendors/jquery-3.2.1.min.js net::ERR_ABORTED 404 (Not Found)

So the name of prefix parkir is included to the assets URL.

Try changing this line:

<script src="{{ asset('assets') }}/js/vendors/jquery-3.2.1.min.js"></script>

to

<script src="{{ asset('/assets/js/vendors/jquery-3.2.1.min.js') }}"></script>

Here, you have just added a / before the assets so that the url starts from root instead of relative current path.

Finally I can solve it! This is because the dashboard.js from template is using require.js to set the required assets with a static path. It look like this Static path of assets

After I added / at the beginning of line like what @Imran said. It works fine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM