title: Laravel4 - Saving a model with multiple relationships/foreign keys
body: <p>I've tried to understand a process of saving a model with multiple relationships but I still can't figure out how to do it "kosher" way.</p>
  
  <p>To begin with - I have an Event model that belongs to a category (Eventcat) and a Location:</p>
  
  <pre><code>// Event.php
  
  class Event extends Eloquent {
  
  protected $table = 'events';
  
  public function location()
  {
      return $this-&gt;belongsTo('Location');
  }
  
  public function eventcat()
  {
      return $this-&gt;belongsTo('Eventcat');
  }
  
  public function users()
  {
      return $this-&gt;belongsToMany('User');
  }
  
  }
  
  // Location.php
  
  class Location extends Eloquent
  {
  
  protected $table = 'locations';
  
  public function events()
  {
      return $this-&gt;hasMany('Event');
  }
  
  }
  
  // Eventcat.php
  
  class Eventcat extends Eloquent
  {
  protected $table = 'eventcats';
  
  public function events()
  {
      return $this-&gt;hasMany('Event');
  }
  }
  </code></pre>
  
  <p>I've seeded the database with a few categories and locations and now I trying to get events saving work. I thought that the <code>$event-&gt;eventcat()-&gt;associate( $eventcat )</code> would work but I got a <code>Call to undefined method eventcat()</code> error.</p>
  
  <pre><code>public function postCreateEvent() {
  
      $event = new Event();
  
      $eventcat = Eventcat::find( Input::get('event-create-eventcat[]') );
      $location = Location::find( Input::get('event-create-location[]') );
  
      $event-&gt;title = Input::get('event-create-title');
      $event-&gt;description = Input::get('event-create-description');
      $event-&gt;price = Input::get('event-create-price');
      $event-&gt;start_date = Input::get('event-create-start_date');
      $event-&gt;end_date = Input::get('event-create-end_date');
  
      $event-&gt;eventcat()-&gt;associate( $eventcat );
      $event-&gt;location()-&gt;associate( $location );
  
      $event-&gt;save();
  
  }
  </code></pre>
  
  <p>I've read the documentation, API and a few threads here but I still can't figure out the best way to deal with this.</p>
  
  <p>Thanks for replies!</p>