【发布时间】:2019-12-17 14:19:46
【问题描述】:
我有两个表故事和精选故事,因此我想在一个请求中将几个故事 ID 添加到精选表。该怎么做?
这是我将单个 id 添加到精选故事表的代码。
public function saveFeatured($id)
{
# code...
$story = $this->getById($id);
$storyId = $story->id;
$featured = new FeaturedStory();
$featured->story_id = $storyId;
$featured->save();
return "Added to featured StoryList";
}
【问题讨论】:
-
为什么不写一个插入查询呢?或类似
DB::table('featuredstory')->insert([['story_id' => $id1], ['story_id' => $id2] ]);或原始查询 -
你打算如何传递这几个故事 ID?通过请求输入?
-
是请求输入