Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel localhost工作正常,但heroku给出了500个错误_Php_Postgresql_Laravel_Heroku - Fatal编程技术网

Php Laravel localhost工作正常,但heroku给出了500个错误

Php Laravel localhost工作正常,但heroku给出了500个错误,php,postgresql,laravel,heroku,Php,Postgresql,Laravel,Heroku,我在一个项目中工作,需要将一些数据从excel转换为数据库。这在本地主机和laravel中运行良好,但当转到heroku时,它会给我一个500内部服务器错误 我在heroku中搜索了一些可能的东西,然后我发现heroku的数据库中有两个从请求中插入的值。这意味着代码循环了两次,但随后出现了错误 我花了4个小时试图找到代码中的错误,但我没有发现发生了什么 代码如下: public function insertFromExcel(){ $excel = new \Maatwebs

我在一个项目中工作,需要将一些数据从excel转换为数据库。这在本地主机和laravel中运行良好,但当转到heroku时,它会给我一个500内部服务器错误

我在heroku中搜索了一些可能的东西,然后我发现heroku的数据库中有两个从请求中插入的值。这意味着代码循环了两次,但随后出现了错误

我花了4个小时试图找到代码中的错误,但我没有发现发生了什么

代码如下:

public function insertFromExcel(){

        $excel = new \Maatwebsite\Excel\Facades\Excel();

        $data = $excel::load('../../../excel_files/relacao_5.xls', function ($reader) {

        })->get();

        foreach ($data as $row) {


            //-----------------------------------------Verifica Setor-------------------------------------

            if(isset($row['nome_setor'])){
                $setor_id = DB::table('setor')->where('nome', '=', $row['nome_setor'])->pluck('id');

                if ($setor_id == null) {
                    $setor_id = DB::table('setor')->insertGetId([
                        'nome' => $row['nome_setor']
                    ]);
                }
            }
            else{
                $setor_id = null;
            }

            //-----------------------------------------Verifica Funcionario--------------------------------

            $funcionario_id = DB::table('funcionario')->where('matricula', '=', $row['codfun'])->pluck('id');



            if ($funcionario_id === null) {
                $funcionario_id = DB::table('funcionario')->insertGetId([
                    'nome' => $row['nome_func'],
                    'matricula' => $row['codfun'],
                    'pis_pasep' => $row['pis_pasep'],
                    'data_admisao' => $row['admissao'],
                    'setor_id' => $setor_id
                ]);
            }
            else{

                $funcionario_pis_pasep = DB::table('funcionario')->where('matricula', '=', $row['codfun'])->pluck('pis_pasep');

                if($funcionario_pis_pasep == null || $funcionario_pis_pasep == 0){
                    DB::table('funcionario')
                        ->where('id', $funcionario_id)
                        ->update([
                            'pis_pasep' => $row['pis_pasep']
                        ]);
                }



                $funcionario_setor = DB::table('funcionario')->where('matricula', '=', $row['codfun'])->pluck('setor_id');

                if($funcionario_setor == null){
                    DB::table('funcionario')
                        ->where('id', $funcionario_id)
                        ->update([
                            'setor_id' => $setor_id
                        ]);
                }
            }


            //-----------------------------------------Verifica Cargos--------------------------------

            if (strpos($row['descrnivcarg'], "GERENTE") !== false) {

                $gerente = DB::table('gerente')
                    ->join('funcionario', 'gerente.funcionario_id', '=', 'funcionario.id')
                    ->where('funcionario.id', '=', $funcionario_id)
                    ->pluck('gerente.id');

                if ($gerente == null) {
                    $user_id = DB::table('usuario')->insertGetId(['senha' => '12345', 'nivel' => 3]);

                    DB::table('gerente')->insert([
                        'funcionario_id' => $funcionario_id,
                        'usuario_id' => $user_id
                    ]);
                }
            }
            if (strpos($row['descrnivcarg'], "COORDENADOR") !== false) {

                $coordenador = DB::table('coordenador')
                    ->join('funcionario', 'coordenador.funcionario_id', '=', 'funcionario.id')
                    ->where('funcionario.id', '=', $funcionario_id)
                    ->pluck('coordenador.id');

                if ($coordenador == null) {
                    $user_id = DB::table('usuario')->insertGetId(['senha' => '12345']);

                    DB::table('coordenador')->insert([
                        'funcionario_id' => $funcionario_id,
                        'usuario_id' => $user_id
                    ]);
                }
            }
            if (strpos($row['descrnivcarg'], "SUPERVISOR") !== false) {

                $supervisor = DB::table('supervisor')
                    ->join('funcionario', 'supervisor.funcionario_id', '=', 'funcionario.id')
                    ->where('funcionario.id', '=', $funcionario_id)
                    ->pluck('supervisor.id');

                if ($supervisor == null) {
                    $user_id = DB::table('usuario')->insertGetId(['senha' => '12345', 'nivel' => 2]);

                    DB::table('supervisor')->insert([
                        'funcionario_id' => $funcionario_id,
                        'usuario_id' => $user_id
                    ]);
                }
            }
            if (strpos($row['descrnivcarg'], "ESTAGIARIO") !== false) {

                $estagiario = DB::table('estagiario')
                    ->join('funcionario', 'estagiario.funcionario_id', '=', 'funcionario.id')
                    ->where('funcionario.id', '=', $funcionario_id)
                    ->pluck('estagiario.id');

                if ($estagiario == null) {
                    $user_id = DB::table('usuario')->insertGetId(['senha' => '12345', 'nivel' => 1]);

                    DB::table('estagiario')->insert([
                        'funcionario_id' => $funcionario_id,
                        'usuario_id' => $user_id
                    ]);
                }
            } else {
                $cargo_id = DB::table('cargo')->where('nome', '=', $row['descrnivcarg'])->pluck('id');

                if ($cargo_id == null) {
                    $cargo_id = DB::table('cargo')->insertGetId(['nome' => $row['descrnivcarg']]);
                }


                $operario = DB::table('operario')
                    ->join('funcionario', 'operario.funcionario_id', '=', 'funcionario.id')
                    ->where('operario.id', '=', $funcionario_id)
                    ->pluck('operario.id');

                if ($operario == null) {

                    DB::table('operario')->insert([
                        'funcionario_id' => $funcionario_id,
                        'cargo_id' => $cargo_id,
                    ]);
                }
            }
        }

        $funcionario_db[] = DB::table('funcionario')->select('matricula', 'nome', 'data_admisao', 'pis_pasep')->get();

        return $funcionario_db;

    }

在花了几个小时试图弄清楚代码是怎么回事之后,我发现这是Apache超时的问题

我找到了答案


信用证:

我发现了500错误的原因。那是因为我把日期配置搞错了

所以,这解决了我的问题

在查找错误的研究过程中,我发现laravel在部署时也有调试消息。因此,我将调试模式更改为true

目录:“laravel/config/app.php”


我还想补充一点,我也遇到了这种情况,但这是因为我忘记为Heroku应用程序添加
APP_键。

对于Heroku中的键问题,请在config/APP.php中添加此代码:

'key' => env('APP_KEY', 'SomeRandomStringSomeRandomString'),
在终端中写入此命令

heroku config:set APP_KEY=SomeRandomStringSomeRandomString

试试这个
heroku config:set APP_DEBUG=true
,然后访问你的应用,看看到底是什么错误。很可能是数据库连接失败或缺少
.env
键。

使用以下命令在heroku中设置2个配置变量:

1
heroku配置:设置APP\u DEBUG=true

2
heroku-config:set-APP\u-KEY=RandomString


设置这些键后,您将能够看到实际的错误,而不是常规的500。

您试图在herokuI上部署的laravel版本使用的是6.5.1 laravel版本有些说明这是一个数据库连接问题,但是我创建了一个postgresq,它在更改htacss文件后仍然不起作用,在运行这些命令之后,你能在@svikramjeet上帮我一下吗?从这里我们可以看到我们的实际错误,你是在看heroku日志吗?t?救了我!正是我需要的
heroku config:set APP_KEY=SomeRandomStringSomeRandomString