How to Implement the PHP framework LaravelEloquentORM to insert data in batches?

Source: Internet
Author: User
Laravel is recently used. If you want to insert nearly a thousand pieces of data in batches, you can insert data in batches by Directly Writing SQL statements. In addition, the framework ORMEloquent provides a Create method: {code...}. This method can easily insert data, but cannot insert data in batches. Based on performance considerations, I do not want to... I recently used Laravel.

If you want to insert nearly a thousand pieces of data in batches, you can insert data in batches by Directly Writing SQL statements.

In addition, the framework ORM Eloquent provides a Create method:

/**     * Save a new model and return the instance.     *     * @param  array  $attributes     * @return \Illuminate\Database\Eloquent\Model|static     */    public static function create(array $attributes)    {        $model = new static($attributes);        $model->save();        return $model;    }

This method can easily insert data, but cannot insert data in batches.
Based on performance considerations, I do not want to write SQL. Does Eloquent have a method for this situation?

Reply content:

Laravel is recently used.

If you want to insert nearly a thousand pieces of data in batches, you can insert data in batches by Directly Writing SQL statements.

In addition, the framework ORM Eloquent provides a Create method:

/**     * Save a new model and return the instance.     *     * @param  array  $attributes     * @return \Illuminate\Database\Eloquent\Model|static     */    public static function create(array $attributes)    {        $model = new static($attributes);        $model->save();        return $model;    }

This method can easily insert data, but cannot insert data in batches.
Based on performance considerations, I do not want to write SQL. Does Eloquent have a method for this situation?

DB::table('users')->insert(array(    array('email' => 'taylor@example.com', 'votes' => 0),    array('email' => 'dayle@example.com', 'votes' => 0),));

Details

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.