title: Laravel Eloquent ORM: trouble with one-to-many using belongs_to()
body: <p>I'm having trouble accessing a relationship in Laravel. Relevant to this question, I have two tables, <code>messages</code> and <code>users</code>. </p>
  
  <p>The <code>messages</code> table looks like:</p>
  
  <pre><code>Messages: id, user_from, user_to, read, message, created_at, updated_at
  </code></pre>
  
  <p>The <code>users</code> table looks like:</p>
  
  <pre><code>Users: id, email, password, name, created_at, updated_at, bio, reputation, last_login_ip, last_seen, active
  </code></pre>
  
  <p>The <code>user_from</code> and <code>user_to</code> columns are both ints that correspond to the <code>id</code> of the user (primary key) that sent the message or who the message was sent to. </p>
  
  <p>The relevant portion of my <code>Message</code> model looks like:</p>
  
  <pre><code>class Message extends Eloquent {
  
      //relationships
      public function user_from() {
          return $this-&gt;belongs_to('User', 'user_from');
      }
  
      public function user_to() {
          return $this-&gt;belongs_to('User', 'user_to');
      }
  }
  </code></pre>
  
  <p>The relevant portion of my <code>User</code> model looks like:</p>
  
  <pre><code>class User extends Eloquent {
  
      //relationships
      public function messages_from() {
          return $this-&gt;has_many('Message', 'user_from');
      }
  
      public function messages_to() {
          return $this-&gt;has_many('Message', 'user_to');
      }
  }
  </code></pre>
  
  <p>In a view, I'm trying to access the user that wrote a message, writing code that looks like:</p>
  
  <pre><code>{{ $message-&gt;user_from-&gt;name }}
  </code></pre>
  
  <p>Which throws an error <code>Trying to get property of non-object</code> on that one line. I know the <code>$message</code> object is defined because all other properties except <code>user_from</code> and <code>user_to</code> are defined and print out perfectly. I've read through the documentation several times and I can't figure out what I have done wrong here... does anyone stick out to anyone? This seems like a textbook example but it doesn't work. </p>
  
  <p>The way I've passed the data to the view is:</p>
  
  <pre><code>$messages = Message::where('user_to', '=', Auth::user()-&gt;id)-&gt;take(20)-&gt;get();
  </code></pre>