php 如何在Laravel Telescope中忽略特定的Mailable类?

rxztt3cl  于 5个月前  发布在  PHP
关注(0)|答案(1)|浏览(49)

我在Laravel 10上安装了望远镜。TelescopeServiceProvider.php中的register()方法目前包含:

Telescope::filter(function (IncomingEntry $entry) {
    if ($this->app->environment('local')) {
        return true;
    }

    return $entry->isReportableException() ||
        $entry->isFailedRequest() ||
        $entry->isScheduledTask() ||
        $entry->hasMonitoredTag() ||
        $entry->isSlowQuery() ||
        $entry->isClientRequest() ||
        ($entry->type === EntryType::REQUEST && in_array('slow', $entry->tags)) ||
        ($entry->type === EntryType::GATE && $entry->content['result'] !== 'allowed') ||
        $entry->type === EntryType::LOG ||
        $entry->type === EntryType::JOB ||
        $entry->type === EntryType::EVENT ||
        $entry->type === EntryType::COMMAND ||
        ($entry->type === EntryType::MAIL && $entry->content['mailable'] !== 'App\Mail\Communication\CommunicationMailable');
});

字符串
正如你从最后几行看到的,我试图记录每个Mailable**,除了**CommunicationMailable类。我目前正在使用Telescope设置的mailable属性进行字符串比较,但我真的不喜欢它,因为如果我改变了mailable类的路径,我必须记住每次都手动更改字符串。有没有更好的方法?

0pizxfdo

0pizxfdo1#

Telescope设置的mailable属性对应于完全限定的类名,因此您可以使用::class常量以编程方式获取它(PHP docs)。在我的例子中:
1.在TelescopeServiceProvider.php中导入CommunicationMailable类:
use App\Mail\Communication\CommunicationMailable;
1.使用::class常量而不是手动编写的字符串(来自问题中的代码):

($entry->type === EntryType::MAIL && $entry->content['mailable'] !== CommunicationMailable::class)

字符串

相关问题