Skip to content

Should we support controlling listener and notification behaviors? #1

@mpyw

Description

@mpyw

Should we support controlling listener and notification behaviors with ShouldAssumeFresh?

<?php

namespace App\Listeners;

use App\Events\PostCreated as PostCreatedEvent;
use App\Notifications\PostCreated as PostCreatedNotification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Mpyw\LaravelCachedDatabaseStickiness\Jobs\ShouldAssumeFresh;

class NotifyPostCreated implements ShouldQueue, ShouldAssumeFresh
{
    use InteractsWithQueue, SerializesModels;

    public function handle(PostCreatedEvent $event): void
    {
        $event->post->community->users->each->notify(new PostCreatedNotification($event->post));
    }
}
<?php

namespace App\Notifications;

use App\Post;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use Mpyw\LaravelCachedDatabaseStickiness\Jobs\ShouldAssumeFresh;

class PostCreated extends Notification implements ShouldQueue, ShouldAssumeFresh
{
    protected $post;

    public function __construct(Post $post)
    {
        $this->post = $post;
    }

    /* ... */
}

It is probably possible to support them. However, it seems almost useless in most cases...

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions