title: Laravel ORM problems
body: <p>I can't figure how to relate these two tables.</p>
  
  <p>I'm new to Laravel and ORM so it's kind of hard to me.
  Here's my 2 tables I'm trying to relate:</p>
  
  <p><img src="https://i.stack.imgur.com/FHlVG.png" alt="tables">
  Tables are called: posts and post_categories
  And here are some of the code:</p>
  
  <pre><code>class Post extends Eloquent {
  
  public function categories()
  {
      return $this-&gt;hasOne('PostCategorie');
      }
  }
  
  class PostCategorie extends Eloquent {
    protected $table = 'post_categories';
  
  public function post()
  {
      return $this-&gt;belongsTo('Post', 'pc_id');
      }
  }
  
  
  public function postCreate()
  {
      $validator = Validator::make(Input::all(), Post::$rules);
  
      if ($validator-&gt;fails()) 
      {
          return Redirect::action('PostsController@getCreate')-&gt;withInput()-&gt;withErrors($validator);
      }
      // Else add to DB
      $categories = Input::get('categories');
  
      $post = new Post;
      $post-&gt;user_id = Auth::user()-&gt;id;
      $post-&gt;title   = Input::get('title');
      $post-&gt;text    = Input::get('text');
      $post-&gt;categories()-&gt;id_1 = $categories[0];
      $post-&gt;save();
  
  }
  </code></pre>
  
  <p>So as you see. I pass values to post and when I save it's ok... but I can't add categories ID to another table...</p>
  
  <p>And also I created dummie entries, and tried to get Post Categories values:</p>
  
  <pre><code>Route::get('/', function()
  {
      $post = Post::find(5);
      echo $post-&gt;title;
      echo $post-&gt;categories()-&gt;id_1;
  });
  </code></pre>
  
  <p>But it failed:</p>
  
  <pre><code>Undefined property: Illuminate\Database\Eloquent\Relations\HasOne::$id_1
  </code></pre>