我在學習Laravel方面很新。我想從數據庫獲取數據並顯示它。我能行。但我想使用標題(從數據庫中提取)作爲鏈接。但後來我得到NotFoundHttpException。 這裏是我的路線NotFoundHttpException Laravel
Route::get('articles', '[email protected]');
Route::get('articles/{id}', '[email protected]');
我控制器
class ArticleController extends Controller
{
public function index()
{
$articles=Article::all();
return view('articles.index', compact('articles'));
} //
public function show($id){
$article=Article::find($id);
return view('articles.show',compact('article'));
}
}
觀點
@extends('new_welcome')
@section('content')
<h1> Articles </h1>
@foreach($articles as $article)
<article>
<h2>
<a href="{url ('/articles',$article->id)}">{{$article->title}}</a>
</h2>
<div class="body">{{ $article->body}}</div>
</article>
@endforeach
@stop
有人可以幫助我在這種情況下?
其一,你有你'指數3'return'語句()'函數... –
錯誤意味着它不能找到路線,什麼是你輸入網址? –
對於兩個,您沒有定義的路由來顯示單個'article',這是'NotFoundHttpException'的來源。 –