2018年12月25日 星期二

Laravel的一些小技巧 - DB::table(一)

//利用兩層foreach,將資料寫入
//
$names = array('a','b','c');$ages = array('1','2','3');
foreach($names as $name)
{
    foreach($ages as $age)
    {
        DB::table('users')->insert(
            array('name' => $name, 'age' => $age)
        );    }
}

來源:stackoverflow - How to insert multiple record in laravel


https://stackoverflow.com/questions/29723865/how-to-insert-multiple-rows-from-a-single-query-using-eloquent-fluent

https://stackoverflow.com/questions/40106855/how-to-insert-multiple-rows-in-laravel-5?rq=1

https://stackoverflow.com/questions/39113682/insert-multiple-records-at-once-with-laravel/39389935

https://stackoverflow.com/questions/1307618/multiple-mysql-insert-statements-in-one-query-php

沒有留言:

張貼留言