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



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire