juliomotol/laravel-channel-attributes

这是我创建的laravel-channel-attributes包

v1.0.0 2023-01-04 12:37 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

使用注解/属性自动注册通道路由!

本包受到spatie/laravel-route-attributes的启发。

已经在使用spatie/laravel-route-attributes?恭喜你,是时候放弃那个./routes目录了!(假设你未使用console.php

use JulioMotol\ChannelAttributes\Attributes\Channel;

#[Channel('foo')]
class FooChannel
{
    //
}

注册方式如下:

Broadcast::channel('foo', FooChannel::class);

安装

您可以通过composer安装此包

composer require juliomotol/laravel-channel-attributes

您可以使用以下命令发布配置文件:

php artisan vendor:publish --tag="laravel-channel-attributes-config"

这是发布配置文件的内容

return [
    /*
     *  Automatic registration of channels will only happen if this setting is `true`
     */
    'enabled' => true,

    /*
     * Channels in these directories that have channel attributes will automatically be registered.
     * You can specify a different namespace other than `\App` by providing a different key.
     *
     * e.g ['\Domain\Post\Broadcasting' => base_path('domain/Post/Broadcasting')]
     */
    'directories' => [
        app_path('Broadcasting'),
    ],
];

使用方法

要添加自动注册的通道,只需将JulioMotol\ChannelAttributes\Attributes\Channel添加到通道类中

您可以通过以下方式添加通道选项:

您可以通过以下方式为模型创建通道:

测试

composer test

变更日志

请参阅CHANGELOG以获取有关最近更改的更多信息。

贡献

请参阅CONTRIBUTING以获取详细信息。

安全漏洞

请查阅我们的安全策略以了解如何报告安全漏洞。

鸣谢

许可协议

MIT许可(MIT)。请参阅许可文件以获取更多信息。