简体   繁体   中英

How to insert Multidimensional array into Database - Using laravel 5.5

Array
(
    [1] => Array
        (
            ['service_id'] => 5bb707ce2c75d216e9383513
            ['service_quantity'] => 1
        )

    [2] => Array
        (
            ['service_id'] => 5bb707ff2c75d2116253f6b6
            ['service_quantity'] => 2
        )

)

How to insert value in Database using laravel. facing problem in foreach loop.

if your data array keys matches exactly with the table column names.
you can do as simple as this.

Db::table('your_table_name')
    ->insert(your_array);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM