我创建了一个这样的表:
帖子
id title
类别
id name
category_post
post_id
category_id
custom_value
类别模型中的:
public function posts()
{
return $this->belongsToMany(Post::class);
}
使用此命令:
$category = Category::find(1);
$posts = $category->posts()->get();
我可以获得所有帖子。
可以在custom_value
中使用每个相关帖子返回category_post
吗?
答案 0 :(得分:0)
您可以使用 #tool "nuget:https://api.nuget.org/v3/index.json?package=GitVersion.CommandLine&version=3.6.2"
if (!BuildSystem.IsLocalBuild)
{
GitVersion(new GitVersionSettings{
OutputType = GitVersionOutput.BuildServer
});
}
GitVersion assertedVersions = GitVersion(new GitVersionSettings
{
UpdateAssemblyInfoFilePath = "./src/Project/AssemblyInfo.cs",
UpdateAssemblyInfo = true,
OutputType = GitVersionOutput.Json,
});
version = assertedVersions.MajorMinorPatch;
semVersion = assertedVersions.LegacySemVerPadded;
milestone = string.Concat("v", version);
方法
withPivot()
或
return $this->belongsToMany(Post::class)
public function posts()
{
return $this->belongsToMany(Post::class)->withPivot('column1','column2');
}
答案 1 :(得分:0)
使用withPivot功能
distance