使用laravel中的find()方法,您可以通過主鍵(默認爲id)進行搜索和查找。 我需要的方法,讓博客模型的所有實例與同一個標籤像laravel中的find()方法
public function blog($tag)
{
$table = Blog::where('tag', $tag)->get();
return view('Blog',[
'blogs'=>$table
]);
}
,這是我的模型細節
Schema::create('blogs', function(Blueprint $table)
{
$table->increments('id');
$table->timestamps();
$table->string('title');
$table->text('body');
$table->text('pics');
$table->string('tag');
});
我用DD(「$表」)看到的結果 結果是空的
Collection {#175 ▼
#items: []
}
什麼是問題? – tkausl
使用where方法時的結果是什麼? –
@tkausl沒有返回dd() –