• 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

wordpress : How to specify the cause "This site can’t be reached"

How can i hide dt if dd got empty value

how to retrieve the first and last instance of a row in pdo dataset

Override default Auth routes in Laravel 7

Google Calendar API batch request PHP

Magento 2 - Controller returning blank page

Laravel 5 session not persisting after user is logged in

IlluminateDatabaseQueryException: SQLSTATE[HY000]: General error: 1 no such table - In clone project

php 7 php.ini upload_max_filesize not working

enroll_table three field fetch to payment form to create payment field in laravel 5.5

Why rand() every time I refresh the page?

Group data in a multidimensional array based on two columns

PHP Discord OAUTH2 code sample not working

How to get median and quartiles/percentiles of an array in JavaScript (or PHP)?

Prestashop webservice API creating cart rules

About Contact Privacy policy Terms and conditions