Waheed Sindhani
Waheed Sindhani

Reputation: 91

Laravel Events and Listeners

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

Upvotes: 1

Views: 3160

Answers (2)

lagbox
lagbox

Reputation: 50531

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.

Upvotes: 5

Severin
Severin

Reputation: 1075

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?

Upvotes: 0

Related Questions