title: laravel 4 Call to a member function posts() on a non-object
body: <p>I followed some tutorial on <a href="http://culttt.com/2013/05/13/setting-up-your-first-laravel-4-model/" rel="nofollow">http://culttt.com/2013/05/13/setting-up-your-first-laravel-4-model/</a> and it just won't work. Here's what I tried:</p>
  
  <p>Post model:</p>
  
  <pre><code>class Post extends Eloquent {
  
    protected $fillable = array('body');
  
    public function user()
    {
      return $this-&gt;belongsTo('User');
    }
  }
  </code></pre>
  
  <p>Routes:</p>
  
  <pre><code>Route::get('/posts',function()
  {
    // Create a new Post
    $post = new Post(array('body' =&gt; 'Yada yada yada'));
    // Grab User 1
    $user = User::find(1);
    // Save the Post
    $user-&gt;posts()-&gt;save($post);
  });
  </code></pre>
  
  <p>User model:</p>
  
  <pre><code>/**
   * Post relationship
   */
  public function posts()
  {
    return $this-&gt;hasMany('Post');
  }
  </code></pre>
  
  <p>For Post model, just simply creating a body column and a <code>user_id</code> column. But, when I browser, display errors: "Call to a member function posts() on a non-object"</p>
  
  <p>Would anyone know what the problem here is? </p>