title: Laravel 5: Event class namespacing / class not found
body: <p>This is more of a PHP namespace question than a Laravel question. I'm creating my first event and handler in Laravel.  I was following the manual pretty closely, along with <a href="https://mattstauffer.co/blog/laravel-5.0-events-and-handlers" rel="nofollow">this nice blog post</a>.  </p>
  
  <p>My EventServiceProvider.php script includes:</p>
  
  <pre><code>/**
   * The event handler mappings for the application.
   *
   * @var array
   */
  protected $listen = [
      'event.name' =&gt; [
          'EventListener'
      ],
      'App\Events\LeadSignup' =&gt; [
          'App\Handlers\Events\SendLeadNotification',
      ],  
  ];
  </code></pre>
  
  <p>I'm not sure if this is correct, but it appears to be working.  I've created the /app/Handlers/Events/SendLeadNotification.php file, which contains:</p>
  
  <pre><code>&lt;?php namespace App\Handlers\Events;
  
  use App\Events\LeadSignup;
  
  use Illuminate\Queue\InteractsWithQueue;
  use Illuminate\Contracts\Queue\ShouldBeQueued;
  
  class SendLeadNotification {
  
      /**
       * Create the event handler.
       *
       * @return void
       */
      public function __construct()
      {
          //
      }
  
      /**
       * Handle the event.
       *
       * @param  LeadSignup  $event
       * @return void
       */
      public function handle(LeadSignup $event)
      {
          print("handling it");
          print_r($event);
          exit(0);
      }
  
  }
  </code></pre>
  
  <p>Also, my /app/Events/LeadSignup.php event code is:</p>
  
  <pre><code>&lt;?php namespace App\Events;
  
  use App\Events\Event;
  
  use Illuminate\Queue\SerializesModels;
  
  class LeadSignup extends Event {
  
      use SerializesModels;
  
      /**
       * Create a new event instance.
       *
       * @return void
       */
      public function __construct()
      {
          //
      }
  
  }
  </code></pre>
  
  <p>My event firing code <em>was</em>:</p>
  
  <pre><code>\Event::fire(new LeadSignup($lead));
  </code></pre>
  
  <p>But this resulted in an error:</p>
  
  <blockquote>
    <p>Class App\Http\Controllers\Site\LeadSignup not found</p>
  </blockquote>
  
  <p>I was able to fix it, finally, by being explicit about the location of the LeadSignup class:</p>
  
  <pre><code>\Event::fire(new \App\Events\LeadSignup($lead));
  </code></pre>
  
  <p>My question is: How can I make the code more beautiful, like in the Laravel documentation, where I can simply call:</p>
  
  <pre><code>\Event::fire(new LeadSignup($lead));
  </code></pre>
  
  <p>?  Or, to ask another way, how can I add the LeadSignup class to my global namespace?  (My apologies iff I got the terminology wrong.)</p>
  
  <h1>Solved!</h1>
  
  <p>lpeharda's answer worked for me.  I am firing the event in my controller code:</p>
  
  <pre><code>\Event::fire(new LeadSignup($lead));
  </code></pre>
  
  <p>Once I added </p>
  
  <pre><code>use App\Events\LeadSignup
  </code></pre>
  
  <p>.. to my controller code, the class could be found.  Here's my complete controller code so that you can see it in action:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers\Site;
  
  use App\Http\Controllers\Controller;
  use App\Events\LeadSignup; // &lt;=== here's the additional code
  
  class LeadsController extends Controller {
  
      public function __construct()
      {
          parent::__construct();      
      }
  
      public function postInsert()
      {
          if(! \Lead::where('email', '=', \Request::input('email'))-&gt;exists()) 
          {
             $lead = \Lead::create(\Request::all());
             \Event::fire(new LeadSignup($lead));
          }
      }
  
  }
  
  ?&gt;
  </code></pre>