1

This is my event class when i use

class EventServiceProvider extends ServiceProvider
    {
        /**
         * The event listener mappings for the application.
         *
         * @var array
         */
        protected $listen = [
            Registered::class    => [
                SendEmailVerificationNotification::class,
            ],
            CategoryEvent::class => [
                CategoryCreatedListener::class,
            ]
        ];

when i runs the following command

php artisan event:generate

it creates the event and listener both in the service provider directory if I put namespace before the event and listener like

App\Events\CategoryEvent::class

It still creates App\Event and App\Event in Service Provider Directory how to Create the Event and Listener Directory up in the App Namespace.

enter image description here

2 Answers 2

5

Sounds like a namespacing issue. You may want to make sure these classes are aliased:

use App\Events\Registered;
use App\Listeners\SendEmailVerificationNotification;
...

otherwise Registered::class is going to be App\Providers\Registered.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks, I've searched google and found a solution and worked for me. event_name and listener name needs to be in quotes and doesn't require the event_name::class part. But then the Pycharm suggests that it should be like **event_name::class' but it works with that warnning.
nothing has to be a string literal you are just not referencing the correct classes when using Class::class, hence the namespacing issue \App\Events\Registered::class === 'App\Events\Registered'
0

It seems that Laravel does not have a custom path support for event generation. So your best bet is probably just to create it manually in the directory you want it and insert it into the EventServiceProvider yourself. It's a bit of manual work, but it doesn't take more than a minute to do.

Similar question has already gone through this: How do I create Events/Listeners with artisan command at sub-directory level?

1 Comment

@ServerinDK I've found the solution thanks for your help. I think the problem is with the syntax caus older version uses different syntax from the laravel 7., and i havn't worked in older version so thats why facing such problems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.