statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
3.58k stars 489 forks source link

[5.x] Auto-discovery of event listeners not working #9862

Closed robdekort closed 2 months ago

robdekort commented 2 months ago

Bug description

In Alpha 1 and 2 I'm using an Event Listener in app/Listeners/PreventDeletingMounts.php. This Listener prevents users from deleting pages that have a mounted collection on them.

namespace App\Listeners;

use Statamic\Events\EntryDeleting;
use Statamic\Facades\Collection;

class PreventDeletingMounts
{
    /**
     * Handle the event.
     */
    public function handle(EntryDeleting $event): void
    {
        if (Collection::findByMount($event->entry)) {
            throw new \Exception(trans('strings.collection_mounted', ['title' => $event->entry['title']]));
        }
    }
}

In Laravel 10 I had to register this in my EventServiceProvider but in Laravel 11 it's supposed to auto-discover those listeners.

It seems in my case this isn't happening. The listener isn't triggering, nor is it listed when running php artisan event:list.

How to reproduce

  1. Create a listener
  2. Don't manually register it
  3. Run php artisan event:list

Logs

No response

Environment

Environment
Application Name: Statamic Peak Development
Laravel Version: 11.3.1
PHP Version: 8.3.4
Composer Version: 2.7.1
Environment: local
Debug Mode: ENABLED
URL: statamic-peak.test
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: statamic
Database: sqlite
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 4
Sites: 1
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.0.0-alpha.2 PRO

Statamic Addons
studio1902/statamic-peak-browser-appearance: dev-feature/v5-support
studio1902/statamic-peak-commands: dev-feature/v5-support
studio1902/statamic-peak-seo: dev-feature/v5-support
studio1902/statamic-peak-tools: dev-feature/v5-support

Installation

Starter Kit using via CLI

Antlers Parser

None

Additional details

No response

robdekort commented 2 months ago

Awesome, this works again!