Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Bulk Insertion in Laravel using eloquent ORM

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 4.38k
    Comment on it

    Insertion is the very basic feature in every project. When we want to do bulk insertion there are n number of ways are available in Laravel to do bulk insertion. Some of the way to bulk insertion are:

    1) By using Raw query in Laravel.
    2) By using eloquent.

    By using Eloquent bulk insertion syntax is:


    Syntax:

    Eloquent::insert()
    


    Example of Eloquent bulk insertion

    $data = array(
        array(
            'name'=>'Coder 1', 'rep'=>'4096',
            'created_at'=>date('Y-m-d H:i:s'),
            'modified_at'=> date('Y-m-d H:i:s')
           ),
        array(
             'name'=>'Coder 2', 'rep'=>'2048',
             'created_at'=>date('Y-m-d H:i:s'),
             'modified_at'=> date('Y-m-d H:i:s')
           ),
        //...
    );
    
    User::insert($data);
    

    Here in the above example User is a eloquent and array data is bulk which we want to insert data.

    By this way we can do bulk insertion.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: