{"id":19235603,"url":"https://github.com/mediumart/notifier","last_synced_at":"2025-04-21T05:32:12.305Z","repository":{"id":62526562,"uuid":"87430259","full_name":"mediumart/notifier","owner":"mediumart","description":"Custom hook names for custom laravel notifications channels","archived":false,"fork":false,"pushed_at":"2021-03-26T14:49:02.000Z","size":74,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-07-23T21:21:12.469Z","etag":null,"topics":["channel","laravel","notifications"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mediumart.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-06T13:04:09.000Z","updated_at":"2021-03-26T14:49:06.000Z","dependencies_parsed_at":"2022-11-02T10:31:24.055Z","dependency_job_id":null,"html_url":"https://github.com/mediumart/notifier","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mediumart%2Fnotifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mediumart%2Fnotifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mediumart%2Fnotifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mediumart%2Fnotifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mediumart","download_url":"https://codeload.github.com/mediumart/notifier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223849363,"owners_count":17213674,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["channel","laravel","notifications"],"created_at":"2024-11-09T16:17:30.936Z","updated_at":"2024-11-09T16:17:31.602Z","avatar_url":"https://github.com/mediumart.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Notifier for laravel 5.3+\n\n[![Build Status](https://travis-ci.org/mediumart/notifier.svg?branch=master)](https://travis-ci.org/mediumart/notifier)\n[![Coverage Status](https://coveralls.io/repos/github/mediumart/notifier/badge.svg?branch=master)](https://coveralls.io/github/mediumart/notifier?branch=master)\n[![License](https://poser.pugx.org/mediumart/notifier/license)](https://packagist.org/packages/mediumart/notifier)\n\n## Description\nLaravel offers a really simple way of defining custom channels for your app notifications. You just have to return the channel class name through the `via` method of any notification: [https://laravel.com/docs/5.4/notifications#custom-channels](https://laravel.com/docs/5.4/notifications#custom-channels).\n\nHowever, using the channel class name inside your notifications objects, can become cumbersome sometimes. \n\nThis package allow you to return a custom hook name for custom notification channel, instead of the channel class name through the `via` method of any of your notifications: \n\n```php\n/**\n * Get the notification channels.\n *\n * @param  mixed  $notifiable\n * @return array|string\n */\npublic function via($notifiable)\n{\n    return ['twitter'];\n}\n```\n\nImagine that you have 10 or 30 notifications class in the same app, that need to be send through a given channel, well now each of the notifications class is tighly coupled with your custom channel class, and if you happen to change the channel class name or may be decide to use a different implementation for the same channel, you will have to open all of your 30 notifications one by one in order to update the returned class name in their `via` method, and that can be very tedious.\n\nAnd frankly, i find it more exciting and really cool to be able to define a custom hook name, sort of like built in notifications channels like 'mail', or 'slack', or 'database', or whatever...\n\nSo if you do like the idea, let's get started!\n\n## Installation\n\nUsing composer:\n```\n$ composer require mediumart/notifier\n```\n\nIf you are using laravel 5.3+ prior to version 5.5, add the service provider in the `providers` array inside `config/app.php`\n```php\nMediumart\\Notifier\\NotifierServiceProvider::class\n```\n## Usage\n\nYou need a class that will act as factory for your custom channel. This factory class can be the custom channel class itself if you want, it just need to implements two public static methods: `canHandleNotification` and `createDriver`. Both methods receive as their only argument the driver hook name that is to be created.\n\nThe first method `canHandleNotification` should return a Boolean(`true` or `false`) to indicate whether or not the factory is able to create the appropriate driver for the notification.\n\n```php\n/**\n * Check for the channel capacity.\n *\n * @param  string $driver\n * @return bool\n */\npublic static function canHandleNotification($driver)\n{\n    return in_array($driver, ['twitter']);\n}\n```\n\nThe second method `createDriver` will be called by the `ChannelManager` if the first one has returned `true` on this factory, and therefore, should return a fully resolved instance of the appropriate driver to use.\n\n```php\n/**\n * Create a new driver instance.\n *\n * @param  $driver\n * @return mixed\n */\npublic static function createDriver($driver)\n{\n    return static::canHandleNotification($driver) \n        ? new static(App::make('someTwitterClient')) : null;\n}\n```\n\nYou can use the provided `notifier:channel` artisan command to generate your channel class, like in the following example:\n\n```\n$ php artisan notifier:channel \u003cchannel_class_name\u003e\n```\n\nA new channel class will be created under `app/Notifications/Channels/\u003cchannel_class_name\u003e.php`.\n\nNow that you have a fully functionnal factory, you need to register it with your application, the easiest way to do that is to create(if not already exists) a **public** property of type `array`, named `$notificationsChannels` inside your `App\\Providers\\AppServiceProvider` and list your factory class name in there.\n\n```php\n/**\n* Notifications channels list.\n*\n* @var array\n*/\npublic $notificationsChannels = [\n    \\Mediumart\\Notifier\\Channels\\TwitterChannel::class,\n];\n```\n\nTo quickly Taste the package use the [Mediumart\\Notifier\\Examples\\FakeScreenChannel](https://github.com/mediumart/notifier/blob/master/src/Examples/FakeScreenChannel.php) example channel.\n\n## License\n\nMediumart Notifier is an open-sourced software licensed under the [MIT license](https://github.com/mediumart/notifier/blob/master/LICENSE.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediumart%2Fnotifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmediumart%2Fnotifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediumart%2Fnotifier/lists"}