-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Laravel 11: Autodiscovery of events is not working anymore #81
Comments
Going forward I would like to introduce a fix for it. However, I am not sure what the desired behavior will be as there is no way anymore to determine if autloading has been manually enabled or disabled. I guess, the best way forward would be a config value in the package where it can be enabled or disabled. What do you think? |
@Wulfheart I'm trying to confirm on my end… but it seems like the |
@inxilpro Isn't there any workaround yet ? |
@mra-dev I have one in a branch but that is not a durable solution. |
I actually found a nice and easy workaround. Just use Laravel 10's default EventServiceProvider & add it to bootstrap/providers.php's Array & set shouldDiscoverEvents to return true. And suddenly everything's just working fine. // app/Providers/EventServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
public function shouldDiscoverEvents(): bool
{
return true;
}
} // bootstrap/providers.php
<?php
use App\Providers\EventServiceProvider;
return [
App\Providers\AppServiceProvider::class,
EventServiceProvider::class,
]; running artisan command: before:
after:
|
Unfortunately this is looking like a harder thing the fix than I hoped. We can’t extend the Laravel service provider any more, so we need to replace more than I expected. I have it partially fixed, but I’m on spring break with my kids, so I have less time to work on it than usual. I’m gonna be on a train for 5 hours today, so hopefully I can get this sorted out then. |
@inxilpro Yeah for sure. How should i do that? Update it from composer.json or ...? |
@inxilpro I almost forgot. I tested it manually by editing vendor files and dump-autoload composer and then got the event:list & it totally worked fine and listed my newly added Events/Listeners. Then i thought maybe i should manually turn Autodiscovery ON with Laravel's EventServiceProvider & add it to providers (Taylor said in his conference video that you can already use old providers if you wish to extend). And it worked like a charm. 😍 Like This: Solution |
@mra-dev you can do |
(I'm going to close this because I just confirmed that #88 works in Laravel 11.) |
The
ModularEventServiceProvider
callsshouldDiscoverEvents
. However, with the new structure it iswhich will always evaluate to false in an inherited class. This means that
modular/src/Support/ModularEventServiceProvider.php
Lines 20 to 26 in 148cfed
will always be false.
The text was updated successfully, but these errors were encountered: