当我在 restful url 中使用参数时,Laravel 试图在错误的目录中查找我的 public 文件
Laravel is trying to find my public files in wrong directory when I use parameter in restful url
我正在尝试使用此 laravel 路径加载页面:
Route::get('products/{category}', "ProductsController@index");
在控制器中,我 return 使用 blade 和母版页的普通视图。问题是视图无法加载它的资源,因为它试图在名为 "products".
的文件夹中找到它们
localhost:8000/products/<and it is searching for the images and styles here instead the public folder>
你知道如何解决这个问题吗?
可能是因为您没有使用绝对URLs来加载您的资源。您可能正在做类似的事情:
<link rel="stylesheet" href="css/style.css">
这将做的是,它将尝试通过将 css/style.css
附加到当前 URL 来加载资源。
例如:
如果您在:http://localhost/pages/home
那么,它可能会在 http://localhost/pages/css/style.css
寻找资源
因此修复:
使用绝对 URLs。
<link rel="stylesheet" href="http://localhost/css/style.css">
这应该可以解决您的问题。
我正在尝试使用此 laravel 路径加载页面:
Route::get('products/{category}', "ProductsController@index");
在控制器中,我 return 使用 blade 和母版页的普通视图。问题是视图无法加载它的资源,因为它试图在名为 "products".
的文件夹中找到它们localhost:8000/products/<and it is searching for the images and styles here instead the public folder>
你知道如何解决这个问题吗?
可能是因为您没有使用绝对URLs来加载您的资源。您可能正在做类似的事情:
<link rel="stylesheet" href="css/style.css">
这将做的是,它将尝试通过将 css/style.css
附加到当前 URL 来加载资源。
例如:
如果您在:http://localhost/pages/home
那么,它可能会在 http://localhost/pages/css/style.css
因此修复:
使用绝对 URLs。
<link rel="stylesheet" href="http://localhost/css/style.css">
这应该可以解决您的问题。