php – Config variable not updated – Laravel-ThrowExceptions

Exception or error:

I have this file “config/custom_params.php”

return [
  'INSERTED_DATA' => 0
];

and I’m using Maatwebsite to import an excel file then insert to database

class StatsImport implements WithHeadingRow, WithChunkReading, WithBatchInserts, ToCollection
{
    /// ..........
     public function collection(Collection $rows)
    {

    $IMPORTED_DATA = Config::get('custom_params.INSERTED_DATA');
    Config::set('custom_params.INSERTED_DATA', $IMPORTED_DATA + count($rows));

    $data = $rows->map(function ($row, $index) {
        $formatted_date = $this->transformDate($row['date_note']);
        if (!$this->days || in_array($row['date_note'], $this->days)) {
            $item = [
                'Type_Note' => $row['type_note'],
                'Utilisateur' => $row['utilisateur'],
                'Resultat_Appel' => $row['resultat_appel'],
                'Date_Nveau_RDV' => $row['date_nveau_rdv'],
                'Heure_Nveau_RDV' => $row['heure_nveau_rdv'],
                'Marge_Nveau_RDV' => $row['marge_nveau_rdv'],
                'Id_Externe' => $row['id_externe'],
                'Date_Creation' => $row['date_creation'],
                'Code_Postal_Site' => $row['code_postal_site'],
                 //  'Departement' => $row['dimension_noteDepartement'],
                'Drapeaux' => $row['drapeaux'],
                'Code_Type_Intervention' => $row['code_type_intervention'],
                'Date_Rdv' => $row['date_rdv'],
                'Nom_Societe' => $row['nom_societe'],
                'Nom_Region' => $row['nom_region'],
                'Nom_Domaine' => $row['nom_domaine'],
                'Nom_Agence' => $row['nom_agence'],
                'Nom_Activite' => $row['nom_activite'],
                'Date_Heure_Note' => $row['date_heure_note'],
                'Date_Heure_Note_Annee' => $row['date_heure_note_annee'],
                'Date_Heure_Note_Mois' => $row['date_heure_note_mois'],
                'Date_Heure_Note_Semaine' => $row['date_heure_note_semaine'],
                'Date_Note' => $formatted_date, // $row['date_note'],
                'Groupement' => $row['groupement'],
                'key_Groupement' => clean($row['groupement']),

                'Gpmt_Appel_Pre' => $row['gpmt_appel_pre'],
                'Code_Intervention' => $row['code_intervention'],
                'EXPORT_ALL_Nom_SITE' => $row['export_all_nom_site'],
                'EXPORT_ALL_Nom_TECHNICIEN' => $row['export_all_nom_technicien'],
                'EXPORT_ALL_PRENom_TECHNICIEN' => $row['export_all_prenom_technicien'],
                //   'EXPORT_ALL_Nom_CLIENT' => $row['dimension_note'EXPORT_ALL_Nom_CLIENT],
                'EXPORT_ALL_Nom_EQUIPEMENT' => $row['export_all_nom_equipement'],
                'EXPORT_ALL_EXTRACT_CUI' => $row['export_all_extract_cui'],
                'EXPORT_ALL_Date_CHARGEMENT_PDA' => $row['export_all_date_chargement_pda'],
                'EXPORT_ALL_Date_SOLDE' => $row['export_all_date_solde'],
                'EXPORT_ALL_Date_VALIDATION' => $row['export_all_date_validation'],
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s')
            ];
            return $item;
        }
    });
    Stats::insert($data->all());
}

so I’m trying to show the user how many rows inserted during the process , that’s why I update the config parameter ‘INSERTED_DATA’ and I’m checking using this route from javascript code :

let coundData = setInterval(function(){
if (sendRequestCountData) {
    $.ajax({
        method: 'get',
        url: APP_URL + '/stats/import-stats/data/count',
        dateType: 'json',
        processData: false,
        contentType: false,
        success: function (data) {
            console.log(data);
             if(request_resolved) {
                 console.log('finished');
                 clearInterval(coundData); // stop the checking after all data inserted
             }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                console.log(jqXHR);
                console.log(textStatus);
                console.log(errorThrown);
            }
        });
    }
}, 2000);

but I always get the default value 0

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *