• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Laravel database insert with combining array and string

phplaravelpostgresql


PHP Snippet 1:

<?php
$attendanceList = [18354012,18354013,18354014,18354015];
$present = "FALSE";

$insertData = array_map(
    fn($el)=>['id'=>$el, 'present'=>$present],
    $attendanceList
);

$db::table("attendance")->insert($insertData); 

PHP Snippet 2:

foreach ($attendanceList as $id) {
    DB::table("attendance")->insert(["id" => $id,"present" => $present]);
}

Related Snippets

Laravel whole batch is cancelled if one Job fails

How in Laravel run JavaScript code stored in php variable?

Can I use a WooCommerce function without any WooCommerce page?

Google Gmail API - How to login programatically?

Method IlluminateAuthRequestGuard::logout does not exist Laravel Passport

Elasticsearch - Want to sort by field in all indices where that particular field available or not if not then avoid it

Form repeater send wrong data with last element in Laravel

Create a new line whenever an array value reaches more than 10 characters

How can I get new CSRF token in LARAVEL by using ajax

shell errors running php exec

RabbitMQ PRECONDITION_FAILED - unknown delivery tag

Malformed MIME header error in Symfony 5.3

Whats the point of running Laravel with the command 'php artisan serve'?

How to prevent phpmailer sending embedded image as an attachment on Gmail?

Which is faster php date functions or carbon?

About Contact Privacy policy Terms and conditions