title: Where to place Laravel Listener logic
body: <p>I would like to associate an Order (ID saved in user session) when a user signs up.</p>
  
  <p>I have created a event and a listener as documented in Laravel site. The problem I'm having is that I'm not sure where the logic to associate the records should go, I initially put this in the <code>Order Controller</code> but the app would try to reference Builder::attachOrderToUser instead. </p>
  
  <p>I moved the method into my Model and it worked however now I'm given the error: </p>
  
  <blockquote>
    <p>Call to undefined method Illuminate\Database\Query\Builder::attach()</p>
  </blockquote>
  
  <p>Could someone point out where this logic should actually go?</p>
  
  <p>Method in Order Model:</p>
  
  <pre><code>/**
   * Attach Order to Customer
   *
   * @param  int  $id
   * @return \Illuminate\Http\Response
   */
  public static function attachOrderToUser($order_id, $user_id)
  {
      // @TODO: Wrap around event handler
      $user = User::find($user_id);
  
      if($user-&gt;order()-&gt;attach($order_id))
          return true;
      else
          return false;
  
  }
  </code></pre>
  
  <p>Here is my listener code:</p>
  
  <pre><code>namespace App\Listeners;
  
  use App\Events\UserQuickSignUpComplete;
  use Illuminate\Queue\InteractsWithQueue;
  use Illuminate\Contracts\Queue\ShouldQueue;
  
  use Auth;
  use Session;
  use App\Order;
  use Illuminate\Http\Request; 
  
  class AttachGuestOrderToUser
  {
      /**
       * Create the event listener.
       *
       * @return void
       */
      public function __construct()
      {
          //
      }
  
      /**
       * Handle the event.
       *
       * @param  UserQuickSignUpComplete  $event
       * @return void
       */
      public function handle(UserQuickSignUpComplete $event)
      {
          // get currently logged in user (was signed in on method that triggers event)
          $user = Auth::user();
          // get order
          $order = Session::get('last_transaction.order_id');
          // attach order to user
          Order::attachOrderToUser($order['order_id'], $user['id']);
      }
  }
  </code></pre>
  
  <p>Any other suggestions would also be appreciated!</p>