praadit
praadit

Reputation: 41

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.

Upvotes: 2

Views: 1899

Answers (2)

praadit
praadit

Reputation: 41

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

Upvotes: 0

Imran
Imran

Reputation: 4750

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.

Upvotes: 1

Related Questions