如何在laravel中播放错误和警告?

问题描述 投票:0回答:1

我正在使用Laravel 5.6和socket.io在我的应用程序的管理面板中广播消息。

在我的应用程序中,需要在将errors and warnings登录到admin之前广播生成的所有laravel logs files

我只想知道如何实现这一功能。自从我成为Laravel框架的新手以来,还有哪些简单的方法。

这是我到目前为止所做的:

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class ErrorBroadcasting implements ShouldBroadcast
{
    use InteractsWithSockets, SerializesModels;

    public $errorContent;

    public function __construct($errorContent)
    {
        $this->errorContent = $errorContent;
    }

    public function broadcastOn()
    {
        return new PresenceChannel('error-broadcasting-channel');
    }
}

这就是我在刀片中消耗通道的方式。

<script>

        window.Echo = new Echo({
            broadcaster: 'socket.io',
            host: window.location.hostname + ':6001',
        });

        var buyer = Echo.channel(`error-broadcasting-channel`);
        buyer.listen("ErrorBroadcasting", e => {
            $('#error_container').append("<div class=\"row chat-snippet\">\n" +
                "                                        <div class=\"col-lg-12\">\n" +
                "                                            <small>Buyer:</small>\n" +
                "                                            <p>"+e.errorContent+"</p>\n" +
                "                                        </div>\n" +
                "                                    </div>");
        });
</script>

这就是我如何修改我的app \ Exceptions \ Handler.php

public function report(Exception $exception)
    {
        if (config('app.mail_exception') && $this->shouldReport($exception)) {
            $this->sendEmail($exception); // sends an email
        }
        broadcast(new ErrorBroadcasting($exception))->toOthers();
        parent::report($exception);
    }
php laravel socket.io broadcast phpwebsocket
1个回答
1
投票

在你的

应用程序/异常/ Handler.php

在render类中的这个类中你可以

 public function report(Exception $exception)
    {

        broadcast($yourEvent)
        parent::report($exception);
    }
© www.soinside.com 2019 - 2024. All rights reserved.