• 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 Multi-language routes without prefix

Why getting "Build step 'Execute shell' marked build as failure" error while creating a backup tar for files

carbon generated datetime not stored correctly into the database

how to prevent float variables displaying as scientific notation when printing [duplicate]

How to fix " Uncaught TypeError: Argument 1 passed to JpGraphException::defaultHandler() " problem in php 7.1.3 and jpgraph 4.2.6?

WordPress ACFNotice: get_field() - We've detected one or more calls to retrieve ACF field values before ACF has been initialized

Combine array with same value and add other [duplicate]

dockerizing Laravel + vue

PHP usort() order in case of equality

Prevent blank space in pdf pages (DomPdf)

Laravel dosen't connect with Oracle

how to use extended ASCII instead of unicode in PHP

OctoberCMS / Anonymous Global Scope

Call to a member function givePermissionTo() on null

How to separate letters and digits from a string in php

About Contact Privacy policy Terms and conditions