Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gabtass9's avatar

can't execute a query from an imports file, before doing the return

Hello everyone, I just built an import file to import excel files and create tuples on the db. but before doing the typical "return", I need to check if one of the parameters I have to insert (used as a foreign key) is present in another table, and if it is not present I have to insert it first in the other table and then use its id as a foreign key. however when I do the query to create the record to be used later as a foreign key, the query fails and the network section tells me "500". how can i solve?

0 likes
2 replies
Sinnbeck's avatar

It's really hard for us to say with 0 code and no error message. Can you start by checking /storage/logs/laravel.log for the error?

gabtass9's avatar

@Sinnbeck thanks for the timeliness. sorry, i'm new to laravel and never heard of the log file. I am attaching the last lines. I realized that by reloading the server though, the log file doesn't have any new data. I am also attaching the import code, I hope you understand.

    /*$spedizione["numero_ddt"]=$values[($user->numero_ddt)-1];
    $spedizione["data"]=Carbon::now();
    $spedizione["colli"]=$values[($user->numero_colli)-1];
    $spedizione["peso"]=$values[($user->peso_colli)-1];
    $spedizione["contrassegno"]=$values[($user->contrassegno)-1];
    $spedizione["note"]=$values[($user->note)-1];
    $spedizione["id_mittente"]=$id;*/
    //da risolvere db
    if ($values[($this->report_id->numero_ddt) - 1] != null) {
        $azienda = Azienda::where('ragione_sociale', '=',$values[($this->report_id->destinatario) - 1])->first();
        if($azienda==null)
        {
            $azienda['ragione_sociale']=$values[($this->report_id->destinatario) - 1];
            $azienda['indirizzo']=$values[($this->report_id->indirizzo_destinatario) - 1];
            $id_luogo = localita::where('cap', '=',$values[($this->report_id->cap_destinatario) - 1])->first();
            $azienda['luogo']=$id_luogo->id;
            $aziendaController = new AziendaController();
            $az=$aziendaController->insertAzienda($azienda);
            dd($az);
        }


        return new Spedizione([
            'numero_ddt' => $values[($this->report_id->numero_ddt) - 1],
            'data' => Carbon::now(),
            'id_mittente' => $this->id,
            'id_destinazione' => $az,
            'colli' => $values[($this->report_id->numero_colli) - 1],
            'peso' => $values[($this->report_id->peso_colli) - 1],
            'contrassegno' => $values[($this->report_id->contrassegno) - 1],
            'note' => $values[($this->report_id->note) - 1],

        ]);
    }
}

}

#55 /home/gabriele/laravel/GeneralServiceUploadDDT/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() #56 /home/gabriele/laravel/GeneralServiceUploadDDT/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(180): Illuminate\Http\Middleware\TrustProxies->handle() #57 /home/gabriele/laravel/GeneralServiceUploadDDT/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}() #58 /home/gabriele/laravel/GeneralServiceUploadDDT/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(165): Illuminate\Pipeline\Pipeline->then() #59 /home/gabriele/laravel/GeneralServiceUploadDDT/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(134): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter() #60 /home/gabriele/laravel/GeneralServiceUploadDDT/public/index.php(51): Illuminate\Foundation\Http\Kernel->handle() #61 /home/gabriele/laravel/GeneralServiceUploadDDT/vendor/laravel/framework/src/Illuminate/Foundation/resources/server.php(16): require_once('...') #62 {main} "}

Please or to participate in this conversation.