mardi 26 novembre 2019

how to add data into to database with foreach in laravel

I want to move all the data from the post table into the CityPost table, I use foreach but why only one data entry,

 $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);

I want all user_id in the PostCity table to be 14



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2QUKQ1h
via IFTTT

Aucun commentaire:

Enregistrer un commentaire