PHP Framework Laravel Eloquent ORM BULK INSERT data, how to implement?

Source: Internet
Author: User
Tags bulk insert
Recently in the use of laravel.

Want to BULK insert nearly thousands of data, know that direct write SQL can be bulk inserted.

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 be inserted in bulk.
Based on performance considerations, do not want to write SQL, do eloquent have a method for this situation?

Reply content:

Recently in the use of laravel.

Want to BULK insert nearly thousands of data, know that direct write SQL can be bulk inserted.

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 be inserted in bulk.
Based on performance considerations, do not want to write SQL, do 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.