doumao1917 2019-06-18 08:09
浏览 351
已采纳

如何将laravel日志文件数据存储到数据库中(5.5)

I need to store the Laravel log into my database . Can you please help me?

  • 写回答

2条回答 默认 最新

  • dsaob80228 2019-07-11 22:23
    关注

    Go to App/Exceptions/Handler.php and then write below code in report() function and define your model as an ErrorLog

            $data = [
                'id'      => $this->createUniversalUniqueIdentifier(),
                'file'    => $exception->getFile(),
                'line'    => $exception->getLine(),
                'message' => $exception->getMessage(),
                'trace'   => $exception->getTraceAsString(),
            ];
    
              $dataArr =['id'     => $data['id'],
                 'file'           => $data['file'],
                 'error_summary'  => 'Line '.$data['line'].' '.$data['message'],
                 'log_trace'      => $data['trace']
                 ];
            ErrorLog::create($dataArr);
    

    Your Model file should be like that ErrorLog.php protected $table = 'logs'; protected $fillable = ['id', 'file', 'error_summary', 'log_trace' ];

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部