通过使用此代码,我尝试从具有相同 id 的 {post} 的帖子表中返回帖子。
Route::model('posts', 'Posts');
Route::get('post/{post}', function(Posts $post){
return $post;
});
但它返回:
Argument 1 passed to {closure}() must be an instance of Posts, string given
怎么了?(我是初学者)
Route::model
中的名称需要与路由中的参数匹配:
Route::model('post', 'Posts');
Route::get('post/{post}', function(Posts $post){
return $post;
});