Dewa Aditya
Dewa Aditya

Reputation: 79

How To Store Data Horizontally From Array In 1 Row

I have array, so i want to store all of in array to DB horizontally

This Is My Code :

$tes = ['table','chair','computer'];
for ($i = 0; $i < count($tes); $i++) {
     $a = $tes[$i];
     DB::table('store')
         ->where('material_number', $material_number)
         ->update([
             'name' => $a,
         ]);
 }

I want to store to row name like this table,chair,computer 1 row in DB

Can anyone help me? Thanks.

Upvotes: 0

Views: 71

Answers (1)

Mohammad
Mohammad

Reputation: 497

checked code :

$tes = ['table','chair','computer'];
$names = implode(',', $tes);

// Output : table,chair,computer

DB::table('store')
   ->where('material_number', $material_number)
   ->update([
       'name' => $names,
   ]);

Upvotes: 2

Related Questions