Search code examples
laravel-5routesassetsprefix

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.


Solution

  • 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