I want to calculate and update remaining leave days from values found in two different tables (php)

I am working on a leave management system whereby when an administrator creates an account, annual leave days are added by default in the staff table. When a staff member applies for leave days to take and has the leave request approved, I want to subtract the taken days in the leave table from the annual leave days assigned in the staff table, after the subtraction I want to update the staff table annual leave days. I am stuck on how I can join the table, calculate from two different tables’ values, and finally update the staff table leave days. Below is my code:

Staff table

staff_id
firstname
lastname
username
dob
doa
password
leave_days

Leave

leaveid
staffid
date_issued
leave_days_taken
status

approve.php

<?php
session_start();

//Getting leaveid from /leave page
$leaveid = $_GET['leaveid'];

//DB Connection
$conn = mysqli_connect('localhost', 'root', '','leavemanagement');
//If approve button was clicked

//Update the status column
$sql = "UPDATE `leave` SET status = 'Approved' WHERE leaveid = '$leaveid'";
$query = mysqli_query($conn, $sql);

if($query == true){?>
    <script>
        alert("Leave request has been approved");
        window.location.href = 'leave.php';
    </script>
<?php
} else{ ?>
    <script>
        alert("Leave request has not been approved");
        window.location.href = 'leave.php';
    </script>
  <?php  } ?>

How to know how many time the same array are present inside another big array in php matrix array

$array = [[121,159,196],[121,159,196],[121,159,196],[121,159,196],[120,158,195],[119,157,194],[118,156,193],[117,155,192],[119,157,194],[118,156,193],[119,157,194],[121,159,196],[122,160,197],[122,160,197],[123,161,198],[124,162,199],[121,159,196],[122,160,197],[122,160,197],[123,161,198],[123,161,198],[123,161,198],[122,160,197],[122,160,197],[121,159,196],[121,159,196],[121,159,196],[121,159,196],[120,158,195],[120,158,195],[120,158,195],[120,158,195],[117,157,193],[118,158,194],[119,159,195],[119,159,195],[119,159,195],[119,159,195],[120,160,196],[121,161,197],[118,158,194],[118,158,194],[118,158,194],[119,159,195],[120,160,196],[121,161,197],[121,161,197],[120,160,196],[118,158,194],[118,158,194],[118,158,194],[117,157,193],[117,157,193],[117,157,193],[116,156,192],[116,156,192],[117,157,193],[117,157,193],[116,156,192],[117,157,193],[117,157,193],[118,158,194],[120,160,196],[120,160,196],[121,159,196],[121,159,196],[120,158,195],[120,158,195],[120,158,195],[119,157,194],[119,157,194],[119,157,194],[121,159,196],[120,158,195],[119,157,194],[118,156,193],[118,156,193],[119,157,194],[120,158,195],[121,159,196],[121,157,193],[121,157,193],[121,157,193],[121,157,193],[120,156,192],[120,156,192],[120,156,192],[120,156,192],[120,156,192],[121,157,193],[121,157,193],[122,158,194],[122,158,194],[121,157,193],[121,157,193],[120,156,192],[120,156,192],[120,156,192],[121,157,193],[121,157,193],[121,157,193],[121,157,193],[120,156,192],[120,156,192],[121,157,193],[122,158,194],[120,156,192],[120,156,192],[120,156,192],[119,155,191],[120,156,192],[119,155,191],[120,156,192],[121,157,193],[121,157,193],[120,156,192],[120,156,192],[120,156,192],[120,156,192],[119,155,191],[123,159,195],[123,159,195]];

$count_array = [];

foreach($array as $item){

if(!isset($count_array[$item])){

$count_array[$item] =1 ;
}

else{

   $count_array[$item]++;
}
}

“Expected : $count_array = [121,159,196] = times , [119,157,194] = times “ecc ecc””

Showing all data with filter from checkbox value in dataTable

i have a table with dataTable, in this table i have a filter with label All, Software Enginer

when i klik the label Software Enginer the value is the result is appropriate with label, but when i klik all label the value in dataTable is missing/zero data

the code of my table like this:

<div class="position-relative content">
            <div class="position-absolute w-100 row" style="z-index: 50;">
                <div class="col-6">
                    <div class="filter-wrapper">
                        <input type="radio" class="filter-checkbox" name="filter" value="all" checked="checked" />
                        All
                        <input type="radio" class="filter-checkbox" name="filter" value="Software Engineer" />
                        Software Engineer
                        <input type="radio" class="filter-checkbox" name="filter" value="Accountant" />
                        Accountant
                    </div>
                </div>
            </div>
        </div>
        <table id="example" class="table" style="z-index: 30;">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th>Age</th>
                    <th>Start date</th>
                    <th>Salary</th>
                    <th>Status</th>
                    <th>Hidden</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Tiger Nixon</td>
                    <td>System Architect</td>
                    <td>Edinburgh</td>
                    <td>61</td>
                    <td>2011/04/25</td>
                    <td>$320,800</td>
                    <td>
                        <div class="badge status-badge badge-info">
                            Draft
                        </div>
                    </td>
                    <td>DRF</td>
                </tr>
                <tr>
                    <td>Garrett Winters</td>
                    <td>Accountant</td>
                    <td>Tokyo</td>
                    <td>63</td>
                    <td>2011/07/25</td>
                    <td>$170,750</td>
                    <td>
                        <div class="badge status-badge badge-info">
                            Draft
                        </div>
                    </td>
                    <td>DRF</td>
                </tr>
            </tbody>
        </table>
    </div>

an then this is my javascript code for dataTable and filter for position field:

$(document).ready(function() {
            dataTable = $("#example").DataTable({
                columnDefs: [{
                    targets: [7],
                    visible: false
                }],
                "bInfo": false,
                "bPaginate": true,
                "bLengthChange": false,
                "buttons": [],
                "ordering": false,
                language: {
                    paginate: {
                        next: '<i class="px-2 py-1.5 rounded-md border-2 border-black fa-solid fa-chevron-right"></i>',
                        previous: '<i class="px-2 py-1.5 rounded-md border-2 border-black fa-solid fa-chevron-left"></i>'
                    }
                },
            });

            $(".filter-checkbox").on("change", function(e) {
                var searchTerms = [];
                $.each($(".filter-checkbox"), function(i, elem) {
                    if ($(elem).prop("checked")) {
                        searchTerms.push("^" + $(this).val() + "$");
                    }
                });
                dataTable.column(1).search(searchTerms.join("|"), true, false, true).draw();
            });
        });

this is my jsdfile:
https://jsfiddle.net/4y9u8xnq/

this is my picture for the result code:
the_result

someone can help. how to show all data when i click the radio button with value all?

PHP – skip else statement on boolean

I have command handler that returns approve param which is boolean type and can be true or false. I have specific setters there and I defined it like:

if ($command->approve()) {
        $schedule->setApproval(true);
        $schedule->setApprovalAt(new DateTime());
    } else {
        $schedule->setApproval(false);
        $schedule->setApprovalAt(null);
}

Is there any cleaner approach to this? Can we skip this kind of repetition and using of else clause?

How to change form action using javascript with two parameter using radio button and select option?

i have two input type to change action parameter on form, i’m using radio button and select option to get the parameter route
this is the code

  <form method="GET" action="{{ route('news.search') }}">
    @method('get')
....
  </form>

this is the first input, i’m using the radio button

              <button type="button" class="btn-icon btn-sm" data-id="{{ $icon->slug }}" id="addIcon">
                  <input type="radio" id="{{ $icon->slug }}" name="icon" class="radio-btn" value="{{ $icon->slug }}" >
                <span class="my-auto" height="16" width="auto">{{ $icon->name }}</span>
              </button>

and this is the second input i’m using select option

            <select class="form-control select-category" name="category" id="category" width="100%">
              <option selected value="all-categories">All Categories</option>
              @foreach($categories as $category)
              <option value="{{ $category->slug }}">{{ $category->name }}</option>
              @endforeach
            </select>

and this is the button input

            <button type="submit" class="btn-search border-0 d-flex justify-content-center btn-block">
              Search
            </button>

i want to change action form input dynamically using select option and radio button iput that i have click it,
expectation form action input is : action=”{{ route(‘news.search’), [$input1,$input2]}}

convert float to string without trim zeros in PHP [duplicate]

how can I convert $float into a string without loosing zeros on right side?

// I want to echo 44.40
$float = 44.40;

echo (string)$float; // Returns 44.4
echo strval($float); // Returns 44.4
echo "$float"; // Returns 44.4

UPDATE
I want this to works without knowing how many decimal digits there are, so using

number_format($float, 2);

is not a solution

Laravel Backpack PermissionManager in crud

They are at the first experiences with laravel 5 and backpack.
I installed the backpack permission manager and I have a questions:

I created permissions / roles and created two users.

  1. in my sidebar_content.blade.php I use conditions correctly
    @role('Admin')
    <!-- Users, Roles, Permissions -->
    <li class="nav-item nav-dropdown">
        <a class="nav-link nav-dropdown-toggle" href="#"><i class="nav-icon la la-users"></i> Authentication</a>
        <ul class="nav-dropdown-items">
            <li class="nav-item"><a class="nav-link" href="{{ backpack_url('user') }}"><i class="nav-icon la la-user"></i> <span>Users</span></a></li>
            <li class="nav-item"><a class="nav-link" href="{{ backpack_url('role') }}"><i class="nav-icon la la-id-badge"></i> <span>Roles</span></a></li>
            <li class="nav-item"><a class="nav-link" href="{{ backpack_url('permission') }}"><i class="nav-icon la la-key"></i> <span>Permissions</span></a></li>
        </ul>
    </li>
    <li class="...
    <li class="...
    @role('Magazzino1')
    <li class="...
    @endrole
    @role('Magazzino2')
    <li class="...
    @endrole

but if i know the example routing
/ admin / user / create I access the page (also for Edit / delete etc …)

How can I allow access only if the user in use is with the “Admin” role?
Thank you

How can i filter out stdClass object to string

I have a PHP script that connects to our hosting provider’s api to get the domain info.
With the following snippet i can get the data in stdClass format how can i apply html / css styling to it?

for each record i want to display it nicly like

  • domain name: | test.com
  • expiraion date: | 2023-06-27T11:26:35:13Z …

Code to get output:

var_dump(
    $json = json_decode($response->getBody()->getContents())

);

Example output:

 object(stdClass)[36]
  public 'domain_name' => string 'test.com' (length=12)
  public 'expiration_date' => string '2023-06-27T11:26:35.13Z' (length=23)
  public 'will_renew' => boolean true
  public 'name_servers' => 
    array (size=2)
      0 => 
        object(stdClass)[34]
          public 'name' => string 'xx.xx.net' (length=15)
          public 'ip' => string 'xx.xxx.xx.xxx' (length=13)
      1 => 
        object(stdClass)[17]
          public 'name' => string 'xxx.xxxxxx.xxx' (length=15)
          public 'ip' => string 'xx.xx.xx.xx' (length=12)
  public 'registrant' => 
    object(stdClass)[30]
      public 'first_name' => string '' (length=0)
      public 'last_name' => string 'xx xx' (length=20)
      public 'address' => string 'xx  21' (length=19)
      public 'postal_code' => string '8470' (length=4)
      public 'city' => string 'Gistel' (length=6)
      public 'country_code' => string 'BE' (length=2)
      public 'email' => string '[email protected]' (length=16)
      public 'fax' => string '+32.xx' (length=12)
      public 'phone' => string '+32.xx' (length=12)
      public 'language_code' => null
      public 'company_name' => string 'xx & xx xx' (length=24)
      public 'enterprise_number' => string 'xx.xx.xx' (length=14)
  public 'can_toggle_renew' => boolean true

PhpOfficePhpSpreadsheetReaderBaseReader::load(): Argument #1 ($filename) must be of type string, null given and few more errors

So I was following this tutorial on how to import Excel file to database using phpspreadsheet but I got a errors like this

Severity: Warning

Message: Undefined array key “import_data_perdana”

Filename: perdana/Perdana.php

Line Number: 168

Backtrace:

File: D:xampphtdocsvobot-cmsapplicationcontrollersperdanaPerdana.php

Line: 168

Function: _error_handler

File: D:xampphtdocsvobot-cmsindex.php

Line: 315

Function: require_once

Severity: Warning

Message: Trying to access array offset on value of type null

Filename: perdana/Perdana.php

Line Number: 168

Backtrace:

File: D:xampphtdocsvobot-cmsapplicationcontrollersperdanaPerdana.php

Line: 168

Function: _error_handler

File: D:xampphtdocsvobot-cmsindex.php

Line: 315 Function:

require_once

Severity: 8192

Message: pathinfo(): Passing null to parameter #1 ($path) of type string is deprecated

Filename: perdana/Perdana.php

Line Number: 169

Backtrace:

File: D:xampphtdocsvobot-cmsapplicationcontrollersperdanaPerdana.php

Line: 169

Function: pathinfo

File: D:xampphtdocsvobot-cmsindex.php

Line: 315

Function: require_once

Severity: Warning

Message: Undefined array key “import_data_perdana”

Filename: perdana/Perdana.php

Line Number: 182

Backtrace:

File: D:xampphtdocsvobot-cmsapplicationcontrollersperdanaPerdana.php

Line: 182

Function: _error_handler

File: D:xampphtdocsvobot-cmsindex.php

Line: 315

Function: require_once

Severity: Warning

Message: Trying to access array offset on value of type null

Filename: perdana/Perdana.php

Line Number: 182

Backtrace:

File: D:xampphtdocsvobot-cmsapplicationcontrollersperdanaPerdana.php

Line: 182

Function: _error_handler

File: D:xampphtdocsvobot-cmsindex.php

Line: 315

Function: require_once

Type: TypeError

Message: PhpOfficePhpSpreadsheetReaderBaseReader::load(): Argument
#1 ($filename) must be of type string, null given, called in D:xampphtdocsvobot-cmsapplicationcontrollersperdanaPerdana.php

on line 182

Filename: D:xampphtdocsvobot-cmsvendorphpofficephpspreadsheetsrcPhpSpreadsheetReaderBaseReader.php

Line Number: 161

Backtrace:

File: D:xampphtdocsvobot-cmsapplicationcontrollersperdanaPerdana.php

Line: 182

Function: load

File: D:xampphtdocsvobot-cmsindex.php

Line: 315

Function:require_once

here’s the controller

<?php
defined('BASEPATH') or exit('No direct script access allowed');
require_once APPPATH . 'core/KBP_Controller.php';

require 'vendor/autoload.php';

use PhpOfficePhpSpreadsheetSpreadsheet;
use PhpOfficePhpSpreadsheetReaderCsv;
use PhpOfficePhpSpreadsheetReaderXls;
use PhpOfficePhpSpreadsheetReaderXlsx;

class Perdana extends KBP_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('./perdana/MPerdana');
        $this->load->model('./fauthz/Users');
        $this->load->library('form_validation');
    }

    public function index()
    {
        if ($this->fauthz->get_user_id() > 0) {
            $data['title'] = 'Perdana';
            $this->load->view('vHeader', $data);
            $this->load->view('vperdana/vindex', $data);
            $this->load->view('vFooter', $data);
        }
    }

    public function importDataPerdana(){
        $import_data_perdana=$_FILES['import_data_perdana']['name'];
        $extension=pathinfo($import_data_perdana,PATHINFO_EXTENSION);

        if($extension=='csv')
        {
            $reader = new PhpOfficePhpSpreadsheetReaderCsv();
        } else if($extension=='xls')
        {
            $reader = new PhpOfficePhpSpreadsheetReaderXls();
        } else
        {
            $reader = new PhpOfficePhpSpreadsheetReaderXlsx();
        }

        $spreadsheet=$reader->load($_FILES['import_data_perdana']['tmp_name']);
        $sheetdata=$spreadsheet->getActiveSheet->toArray();
        echo '<pre>';
        print_r($sheetdata);
    }

}

and here’s the view

<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<div class="content-wrapper">
    <section class="content-header">
        <selection class="content-body">
            <div class="row">
                <div class="col-md-12">
                    <div class="box box-primary" style="min-height: 0px;">

                        <form id="formImportPerdana" action="<?php echo site_url('/perdana/Perdana/importDataPerdana'); ?>" method="post"></form>

                        <form action="<?php echo site_url('/perdana/Perdana/tambahData'); ?>" method="post">
                            <div class="box-body">
                                <?php if (validation_errors()) : ?>
                                    <div class="alert alert-danger" role="alert">
                                        <?= validation_errors(); ?>
                                    </div>
                                <?php endif; ?>
                                <div class="list-content">
                                    <a href="#listone" data-toggle="collapse" aria-expanded="true" aria-controls="listone" class="">Perdana<i class="fa fa-chevron-down"></i></a>
                                    <div class="collapse in" id="listone" aria-expanded="true" style="">
                                        <div class="list-box">
                                            <div class="box-body" style="padding:25px">
                                            
                                                <div class="form-group">
                                                    <label for="importDataPerdana">Import</label>
                                                    <input name="import_data_perdana" id="importDataPerdana" type="file" class="form-control" form="formImportPerdana">    
                                                </div>

                                                <div class="form-group">
                                                    <label>Operator</label>
                                                    <select class="form-control" name="operatorPerdana" id="operatorPerdana" data-live-search="true">
                                                        <option value="">--- Pilih Operator ---</option>
                                                        <option value="Telkomsel">Telkomsel</option>
                                                        <option value="Indosat Ooredoo">Indosat Ooredoo</option>
                                                        <option value="Tri">Tri</option>
                                                        <option value="XL">XL</option>
                                                        <option value="AXIS">AXIS</option>
                                                        <option value="Smartfren">Smartfren</option>
                                                    </select>

                                                </div>
                                                <div class="form-group">
                                                    <label>Nomor</label>
                                                    <div class="input-group">
                                                        <div class="input-group-addon">
                                                            <span>(+62)</span>
                                                        </div>
                                                        <input class="form-control" type="number" name="nomerPerdana" id="nomerPerdana" placeholder="08129">
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label>Harga</label>
                                                    <div class="input-group">
                                                        <div class="input-group-addon">
                                                            <span>Rp.</span>
                                                        </div>
                                                        <input class="form-control" type="text" name="hargaPerdana" id="hargaPerdana" onkeyup="convertToRupiah(this)" placeholder="10.000">
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label>Date:</label>
                                                    <div class="input-group date">
                                                        <div class="input-group-addon">
                                                            <i class="fa fa-calendar"></i>
                                                        </div>
                                                        <input type="text" class="form-control pull-right" name="date_perdana" id="date_perdana">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="list-content">
                                    <a href="#listtwo" data-toggle="collapse" aria-expanded="false" aria-controls="listtwo" class="collapsed">Pulsa <i class="fa fa-chevron-down"></i></a>
                                    <div class="collapse" id="listtwo" aria-expanded="false" style="height: 0px;">
                                        <div class="list-box">
                                            <div class="box-body" style="padding:25px">
                                                <div class="form-group">
                                                    <label>Operator</label>

                                                    <select class="form-control" name="operatorPulsa" id="operatorPulsa" data-live-search="true">
                                                        <option value="">--- Pilih Operator ---</option>
                                                        <option value="Telkomsel">Telkomsel</option>
                                                        <option value="Indosat Ooredoo">Indosat Ooredoo</option>
                                                        <option value="Tri">Tri</option>
                                                        <option value="XL">XL</option>
                                                        <option value="AXIS">AXIS</option>
                                                        <option value="Smartfren">Smartfren</option>
                                                    </select>

                                                </div>
                                                <div class="form-group">
                                                    <label>Nomor</label>
                                                    <div class="input-group">
                                                        <div class="input-group-addon">
                                                            <span>(+62)</span>
                                                        </div>
                                                        <input class="form-control" type="number" name="nomerPulsa" id="nomerPulsa" placeholder="812992">
                                                    </div>

                                                </div>
                                                <div class="form-group">
                                                    <label>Harga</label>
                                                    <div class="input-group">
                                                        <div class="input-group-addon">
                                                            <span>Rp.</span>
                                                        </div>
                                                        <input class="form-control" type="text" name="hargaPulsa" id="hargaPulsa" onkeyup="convertToRupiah(this)" placeholder="10.000">
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label>Nominal Pulsa</label>
                                                    <div class="input-group">
                                                        <div class="input-group-addon">
                                                            <span>Rp.</span>
                                                        </div>
                                                        <input class="form-control" type="text" name="nominalPulsa" id="nominalPulsa" onkeyup="convertToRupiah(this)" placeholder="10.000">
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label>Date:</label>
                                                    <div class="input-group date">
                                                        <div class="input-group-addon">
                                                            <i class="fa fa-calendar"></i>
                                                        </div>
                                                        <input type="text" class="form-control pull-right" name="date_pulsa" id="date_pulsa">
                                                    </div>
                                                </div>

                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="list-content">

                                    <a href="#listthree" data-toggle="collapse" aria-expanded="false" aria-controls="listthree" class="collapsed">Kuota <i class="fa fa-chevron-down"></i></a>
                                    <div class="collapse" id="listthree" aria-expanded="false" style="height: 0px;">
                                        <div class="list-box">
                                            <div class="box-body" style="padding:25px">
                                                <div class="form-group">
                                                    <label>Operator</label>

                                                    <select class="form-control" name="operatorKuota" id="operatorKuota" data-live-search="true">
                                                        <option value="">--- Pilih Operator ---</option>
                                                        <option value="Telkomsel">Telkomsel</option>
                                                        <option value="Indosat Ooredoo">Indosat Ooredoo</option>
                                                        <option value="Tri">Tri</option>
                                                        <option value="XL">XL</option>
                                                        <option value="AXIS">AXIS</option>
                                                        <option value="Smartfren">Smartfren</option>
                                                    </select>

                                                </div>

                                                <div class="form-group">
                                                    <label>Nomor</label>
                                                    <div class="input-group">
                                                        <div class="input-group-addon">
                                                            <span>(+62)</span>
                                                        </div>
                                                        <input class="form-control" type="number" name="nomerKuota" id="nomerKuota" placeholder="812992">
                                                    </div>

                                                </div>
                                                <div class="form-group">
                                                    <label>Harga</label>
                                                    <div class="input-group">
                                                        <div class="input-group-addon">
                                                            <span>Rp.</span>
                                                        </div>
                                                        <input class="form-control" type="text" name="hargaKuota" id="hargaKuota" onkeyup="convertToRupiah(this)" placeholder="10.000">
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label>Nominal Kuota</label>
                                                    <div class="input-group">
                                                        <div class="input-group-addon">
                                                            <span>Rp.</span>
                                                        </div>
                                                        <input class="form-control" type="text" name="nominalKuota  " id="nominalKuota" onkeyup="convertToRupiah(this)" placeholder="10.000">
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label>Date:</label>
                                                    <div class="input-group date">
                                                        <div class="input-group-addon">
                                                            <i class="fa fa-calendar"></i>
                                                        </div>
                                                        <input type="text" class="form-control pull-right" name="date_kuota" id="date_kuota">
                                                    </div>
                                                </div>
                                            </div>

                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="box-footer">
                                <button type="submit" id="simpan" class="btn btn-primary" style="float: right;">Simpan</button>
                            </div>
                        </form>

                    </div>
                </div>
            </div>

        </selection>
    </section>
</div>

I’m really new at this, can anybody kind enough to tell me what’s happened and tell me the solution. thank you and I’m so sorry I can’t include the code because stackoverflow keep giving me error

pick 2nd word from right side (Like – ADMINISTRATOR). and if 2nd word character less then 5 then add character from (“LGRNH”). in php

$str = "BFEBFBFF0001067A-00AC1AC2-TOBEFILLEDBYOEM-ADMINISTRATOR-STE"; 
 if( str_ends_with($Machineid,'-STE')) {
        // echo " Saral Typing Exam";
        $s_plans = substr($Machineid,5,-5);
        echo "n";
        echo $s_plans;

pick 2nd word from right side (Like – ADMINISTRATOR). and if 2nd word character less then 5 then add character from (“LGRNH”). in php .

how to join 3 table wherehas eloquent using laravel

for example I have 3 tables and that tables has a relation,

Table A

  • id
  • name

Table B

  • id
  • tableId_A
  • tableId_C

Table C

  • id
  • name

i’m using table C but i want to search items by request name that have the same name as in table A using query eloquent
and this is the query, i’m using a laravel

$this->model->query()
            ->withWhereHas('tableB', function($query) use ($names) {
            $query->tableB->where('name', 'LIKE', "%{$names}%");})

how to fix it using eloquent where has used 3 tables relation?

Handle TRUNCATE INSERT RACE

I have a php-script that is to get data and insert that data into an MSSQL (v12) table. The table should be emptied before inserting.

I have:

$connPdo->query("TRUNCATE TABLE [Table]");

    $get_data = callAPI('GET', 'https://api...);
    $response = json_decode($get_data, true);

        foreach ( $response['FOO'] as $Lines ) 
        $Proginsert = $connPdo->query("INSERT INTO [Table] (FEE, FIE) 
        VALUES('".$Lines[A]."','" .$Lines[B]."')");

Problem is that sometimes it works OK, sometimes the TRUNCATE is not finished before the first INSERT arrives to the database which leads to some old data beeing kept in the table.
I need a way to hold off the INSERTS until the TRUNCATE is done.

QBW file via ajax

I try to upload a huge qbw file in chunks using this function.
But the file type is empty and when
I try to open it with a dedicated program , it tells me that the file has an unexpected format.
Also after merging the chunks, they are merged into one huge file,
but the file has 0 kb size.
I tried many contentType,
headers and reader methods to read chunks but the same result.
Can anyone knows what is wrong ?

// slice files in chunk chunky

      chunky : function(file, loadedSize) 
{ let chunkSize = 1048576 ; //1024*1024; size of one chunk var totalFileSize = file.size; // total size of file 
var noOfChunks = Math.ceil(totalFileSize/chunkSize); 
let reader = new FileReader();
let blob = file.slice(loadedSize, chunkSize); //a single chunk in starting of step size let requestNumber = 1;
 reader.readAsBinaryString(blob); // reader.readAsDataURL( blob ); console.log('totalSize'+totalFileSize); 
console.log('noOfChunksTosend' + requestNumber);
 reader.onloadend = function (event)
 {
 if (event.target.readyState === FileReader.DONE) { //read request completed // no more chunks to send 
if(event.target.result) 
{ console.log('loadedSize' + loadedSize); console.log('rezult::' + event.target.result);
 var dataToBeSent = { 
bloby: event.target.result, 
 fileName: file.name, 
fileType: file.type, // empty ?? fileSize: totalFileSize, 
loadedSize: loadedSize,
 requestNumber: requestNumber
 } 
jQuery.ajax({ 
url: IntegrationServer.path + '/uploadfileInChuncks', 
type: "POST",
 method: 'POST', 
data: dataToBeSent, 
// contenttype: "multipart/form-data", 
processData: false, 
contentType: false,
 // this dataType: 'json',
 cache:false, }).done(function (response)
 { console.log('received response: ' + response);