• 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

Custom API and cunsuming in php?

Laravel Get Days In Month From Month Number?

Redirect to previous page with php

Laravel Pagination links() not working

Guzzle Not Sending Grant Type to Laravel Passport

Install mysql client in docker image

Warning file_get_contents () failed to open stream: HTTP request failed! HTTP/1.0 402 Payment Required

Laravel - Implicit route model binding with soft deleted data

(Laravel) How to delete multiple models including optional relationships?

IlluminateDatabaseQueryException could not find driver [duplicate]

Laravel Collections. Is there some kind of assertStructure method?

XAMPP keeps showing Dashboard/Welcome Page instead of the Configuration Page

Warning: A non-numeric value encountered

PHP Discord OAUTH2 code sample not working

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

About Contact Privacy policy Terms and conditions