liran-co / laravel-notification-subscriptions Goto Github PK
View Code? Open in Web Editor NEWSubscription management for Laravel notifications.
License: MIT License
Subscription management for Laravel notifications.
License: MIT License
When I send a notification, the EventServiceProvider boot method is called, however, the listener is not called.
When I place a log::debug in the boot method, it shows up, but in the listener it does not show up
And ofcourse the unsubscribes are not handled and the mail is sent out
Any idea why (running L8)
Can you please update your package code and dependencies to be compatible with Laravel 9.x.?
I haven't source dived to check on this, but is this package compatible with PHP 8? It's locked into the 7.x branch because of the composer settings, so it's throwing a warning when I try to update to PHP 8.
I was wondering if it's just a case of needing to add that to composer.json
or if there are things that need to be changed in the code.
Hello,
Thanks for the package - this is the exact functionality I was looking to implement.
I have created a base notification class that I plan to use for all notifications on a given Class. The base notification implements an interface which declares getSubscriptionModel().
The goal is to be able to unsubscribe from notifications for any particular Model of that class; however, if it's setup like this, it breaks attempts to unsubscribe from the Notification class itself.
ex:
interface CanUnsubscribe
{
public function getSubscriptionModel($notifiable) : \Illuminate\Database\Eloquent\Model;
}
abstract class RequestNotification extends Notification implements ShouldQueue, CanUnsubscribe
{
use Queueable;
public Request $request;
public bool $ignoreSubscriptions;
public function __construct(Request $request, $ignore = false)
{
$this->request = $request;
$this->ignoreSubscriptions = $ignore;
}
public function getSubscriptionModel($notifiable): \Illuminate\Database\Eloquent\Model
{
return $this->request;
}
}
class NotifyRequestStateChanged extends RequestNotification
{
// ... concrete notification ....
}
Then if you try
$user->unsubscribe(NotifyRequestStateChanged)
The user will still receive the notification unless you specify the model in the unsubscribe call.
I would expect that if you've unsubscribed from a notification, you should not receive that notification, regardless of it's implementation of the getSubscriptionModel() function or not.
Laravel 11 support would be great. I think it sould just be an addition to composer.json
I followed the instructions in the readme to unsubscribe a user from a specific channel, I am trying to unsubscribe a user from mail but the mail is sent anyway. I even tried switching to OptInSubscriotion()
which should prevent all mails from sending by default but the mails still get sent. I followed the steps strictly and have gone over it several times. Not sure what is wrong.
EDIT:
Turns out I wasn't importing the necessary classes properly... silly😅.
When calling isSubscribed on a user->with('NotificationSubscriptions)
The following returns an n+1 problem, as you are requerying instead of using the loaded relations
return $this->notificationSubscriptions()->where('type', $type)->where('channel', $channel)->model($model)->first();
This package seems to be locked to Laravel 6.x and 7.x via composer. Is it compatible with 8.x and can composer be updated to reflect this?
It would be good if users could subscribe or unsubscribe from panel.
In my App/Providers/EventServiceProvider.php
, I was listening to the NotificationSending
event to do some checks before sending a notification as follows:
// namespace App\Providers;
protected $listen = [
'Illuminate\Notifications\Events\NotificationSending' => [
'App\Listeners\NotificationSendingListener',
],
];
After I installed this package, my App\Listeners\NotificationSendingListener
does not seem to work.
I believe, it is being overridden by the package because the package is listening to the same event as:
// namespace LiranCo\NotificationSubscriptions\Providers;
protected $listen = [
'Illuminate\Notifications\Events\NotificationSending' => [
'LiranCo\NotificationSubscriptions\Listeners\NotificationSendingListener',
],
];
Maybe the same array key issue and the first value gets overridden by the second.
As the protected $listen
is an associative array and using the same array key results in the last key-value pair actually being registered and ignoring any previous ones.
As we know the listener LiranCo\NotificationSubscriptions\Listeners\NotificationSendingListener
checks if the user has unsubscribed from the notification and returns false
which suppress that notification from being processed and sent out to the user. All good here.
But if user has not unsubscribed from the notification, this class returns $event
.
And this causes the other listeners for the same event NotificationSending
not processed.
Returning void return;
instead of return $event
in the handle method of LiranCo\NotificationSubscriptions\Listeners\NotificationSendingListener
class resolves the issue.
@liran-co I'll open a pull request soon for a review.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.