iracode-com / filament-notification
Installs: 21
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Type:filament-plugin
Requires
- php: >=8.1
- filament/filament: >=3.2
- guzzlehttp/guzzle: ^7.8
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
- irazasyed/telegram-bot-sdk: ^3.14
- laravel/framework: ^8.0|^9.0|^10.0|^11.0
- spatie/laravel-package-tools: ^1.16.4
- tzsk/sms: ^8.0
Requires (Dev)
- ext-soap: *
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^7.0|^8.0|^9.0
README
First Install Package
$ composer require iracode-com/filament-notification
Add Provider To Providers Project
laravel 11
bootstrap/providers.php
<?php return [ App\Providers\AppServiceProvider::class, App\Providers\Filament\AdminPanelProvider::class, \IracodeCom\FilamentNotification\FilamentNotificationServiceProvider::class, // <--- ];
Laravel 10 or ....
config/app.php
'providers' => ServiceProvider::defaultProviders()->merge( [ \IracodeCom\FilamentNotification\FilamentNotificationServiceProvider::class, // <--- ] )->toArray(),
Publish The Provider Files To Project
php artisan vendor:publish --provider=IracodeCom\FilamentNotification\FilamentNotificationServiceProvider
Run Artisan Migrate For Add Columns To Table Users
php artisan migrate
Update Fillable To Model app/Models/User.php
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; class User extends Authenticatable { use HasFactory, Notifiable; // <-- Notifiable is important protected $fillable = [ // ... 'prefers_bale', 'prefers_telegram', 'prefers_sms', 'telegram_chat_id', 'bale_chat_id', 'phone' // ... ]; public function routeNotificationForSms() { return $this->phone; } public function routeNotificationForBale() { return $this->bale_chat_id; } public function routeNotificationForTelegram() { return $this->telegram_chat_id; } }
Add Plugin Filament To List app/Providers/Filament/AdminPanelProvider.php
<?php namespace App\Providers\Filament; use IracodeCom\FilamentNotification\FilamentNotificationPlugin; use Filament\PanelProvider; use Filament\Panel; class AdminPanelProvider extends PanelProvider { public function panel( Panel $panel ) : Panel { return $panel ->plugins( [ FilamentNotificationPlugin::make(), // <--- FilamentNotificationPlugin::make() ->setGridColumnConfig() // optional ->setGridColumnNotify() // optional ->setSectionColumnSpan() // optional ->usingPage() // optional ] ) ; } }
Config .env
File
SMS_DRIVER=log SMS_USERNAME= SMS_PASSWORD= SMS_NUMBER= TELEGRAM_BOT_TOKEN= BALE_BOT_TOKEN=
how to use
For Example Create One Notification
Form Laravel:
You Can Create Your Custom Notification Also
<?php namespace IracodeCom\FilamentNotification\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use IracodeCom\FilamentNotification\Notifications\Channels\BaleChannel; use IracodeCom\FilamentNotification\Notifications\Channels\FilamentChannel; use IracodeCom\FilamentNotification\Notifications\Channels\FarazSmsPatternChannel; use IracodeCom\FilamentNotification\Notifications\Channels\TelegramChannel; class UserNotification extends Notification { use Queueable; /** * Create a new notification instance. */ public function __construct( protected string $message, protected bool $bale = true, protected bool $telegram = true, protected bool $sms = true ) { } /** * Get the notification's delivery channels. * * @return array<int, string> */ public function via( $notifiable ) : array { $channels = [ FilamentChannel::class ]; if ( $notifiable->prefers_telegram && $this->telegram ) { $channels[] = TelegramChannel::class; } if ( $notifiable->prefers_sms && $this->sms ) { $channels[] = FarazSmsPatternChannel::class; } if ( $notifiable->prefers_bale && $this->bale ) { $channels[] = BaleChannel::class; } return $channels; } public function toTelegram( $notifiable ) : array { return [ 'text' => $this->message, ]; } public function toSms( $notifiable ) : array { return [ 'body' => $this->message, ]; } public function toBale( $notifiable ) : array { return [ 'text' => $this->message, ]; } public function toFilament( $notifiable ) : array { return [ 'body' => $this->message, ]; } }
Example Code Using:
use IracodeCom\FilamentNotification\Notifications\UserNotification; $user = \App\Models\User::find( 1 ); $user->notify( new UserNotification( 'Hello' ) );
use IracodeCom\FilamentNotification\Notifications\UserNotification; use \App\Models\User; foreach ( User::all() as $user ) { $user->notify( new UserNotification( 'Welcome' ) ); } // Or User::get()->each->notify( new UserNotification( 'Welcome' ) );
If You Like Make New Notification, Can Use Thia Command
php artisan make:notification YOUR_NOTIFICATION_NAME
SetWebHook Telegram
Run The This Url
domain.com/telegram/set-webhook
Security
If you discover any security related issues, please email aliw1382@gmail.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.