在home页面,我可以访问bootstrap、javascript和image等资源,然后从home访问news页面,然后从newspage访问newsDetail 页面。但是在这个newsDetails页面中,它访问了错误的资源地址。 例子 : 在主页,它正确访问 http://localhost:8000/css/bootstrap.min.css http://localhost:8000/img/Logo.png
但是在newsDetails页面,它访问http://localhost:8000/news/css/bootstrap.min.css http://localhost:8000/news/img/Logo.png
地址上有以下“新闻”。 这是我的路线
Route::get('/','HomeController@showHome');
Route::get('news','NewsController@showNews');
Route::get('news/{id}','NewsController@showNewsDetails');
Controller
public function showNewsDetails($id)
{
$content = News::find($id);
return view('newsDetails',compact('content'));
}
有人能帮忙吗?
最佳答案
你应该将所有 CSS/JS 的东西放到 public 文件夹中,你可以使用 asset()
helper 访问它
<link href = "{{ asset('public') }}/css/bootstrap.css" rel = "stylesheet" type = "text/css">
对于标志
<img src="{{ asset('public') }}/img/Logo.png" />
关于php - 使用路由 Laravel 5.2 时访问资源时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48800959/