• 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

php code to send checkbox form results to email

HTML + PHP + PHPMAILER

Batch request Google Calendar php API

Laravel Collections. Is there some kind of assertStructure method?

How to get Laravel's CSRF Token from Another Website?

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'posts.post' doesn't exist

Webscraping Symfony/Panther: Can't get HTML

Laravel SQL query midnight time not showing

Any AWS EB Laravel route getting 404 Not Found nginx/1.16.1

Check if a string contain multiple specific words

Laravel Nova Dependency Container what are the allowed resource properties other than id in dependsOn

How to get rid of ampersand using WP Nonce URL and WP Redirect or PHP header

How to write PHP in XSLT

Webscraping Symfony/Panther: Can't get HTML

Using PHP to connect to a remote MSSQL database

About Contact Privacy policy Terms and conditions