Insert batch in Laravel 5

2019-09-18 20:44发布

问题:

I am using laravel 5. I have tried to insert the following data in laravel using Insert. But not working anymore.

I have $permission array which contains the following array detials.

Array
(
[0] => Array
    (
        [permission_id] => 1
        [role_id] => 1
    )

[1] => Array
    (
        [permission_id] => 2
        [role_id] => 1
    )

[2] => Array
    (
        [permission_id] => 3
        [role_id] => 1
    )

[3] => Array
    (
        [permission_id] => 4
        [role_id] => 1
    )
)

DB::table('permission_role')->insert($permission)

回答1:

array
(
    array
    (
        [permission_id] => 1,
        [role_id] => 1,
    ),

    array
    (
        [permission_id] => 2,
        [role_id] => 1,
    ),
    array
    (
        [permission_id] => 3,
        [role_id] => 1,
    ),
    array
    (
        [permission_id] => 4,
        [role_id] => 1,
    )
)