poison pawn
poison pawn

Reputation: 57

If there is a real path under the public folder, same as the route path

I have some folders under public folder. For example

public/games/game1
public/games/game2

and this folder includes css, js, sprites etc.

And I have routes (in web.php)

Route::prefix('games')->group(function (){
 Route::get('game1',[GameController::class, 'game1Index'])->name('game1');
 Route::get('game2',[GameController::class, 'game2Index'])->name('game2');
});

Whenever I call these routes, it searches index.php under "public/games/game..n" folder without ever visiting gamecontroller. And it gives an error saying "page not found".

If i change the name of my route (games -> game-list). For example

Route::prefix('game-list')->group(function (){
     Route::get('game1',[GameController::class, 'game1Index'])->name('game1');
     Route::get('game2',[GameController::class, 'game2Index'])->name('game2');
    });

It goes to the GameController.php and works correctly. but this time the external, relative links I gave for javascript and css files explode.

To solve this, I apply a solution to the links one by one (inside javascript path, and css path, adding to ../games/game1). This time it works completely, however, it bothers me that it is this way. for example:

s_oSpriteLibrary.addSprite("mask_slot","../games/game1/sprites/mask_slot.png");

Is there any other decent solution?

Upvotes: 0

Views: 367

Answers (1)

Innovin
Innovin

Reputation: 830

Your routes should not point to folders that already exist in your public path.

You cannot have a public path with the same name as your route because Laravel will not know whether "/games" is for the controller, or for the styles or js etc.

That is why the very first instance of your web.php was not working and the second one did. The games folder already exists in your public path.

Instead of doing that, you should put your css js sprites folders and files in an assets folder instead.

Upvotes: 1

Related Questions