使用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() –