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

Waheed Sindhani
  • 91
  • 1
  • 13

2 Answers2

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.

lagbox
  • 48,571
  • 8
  • 72
  • 83
  • 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. – Waheed Sindhani Aug 10 '20 at 09:40
  • 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'` – lagbox Aug 10 '20 at 09:52
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?

Severin
  • 962
  • 5
  • 21
  • @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. – Waheed Sindhani Aug 10 '20 at 09:43