【发布时间】:2019-11-27 03:52:55
【问题描述】:
我想将post表中的所有数据移到CityPost表中,我用foreach但是为什么只有一个数据条目,
$store = new CityPost;
$post = Post::all();
foreach($post as $p){
$store->user_id = 14;
$store->title = $v->title;
$store->desc = $v->desc;
$store->save();
}
dd($store);
我希望PostCity 表中的所有user_id 都是14
【问题讨论】:
-
因为您在第一次保存后只创建了一个新模型实例,所以它现在有一个 id,之后每次调用保存只是对同一记录的更新
标签: php mysql sql laravel laravel-5