title: How to add in a model collection an associated row of related a model in laravel
body: <p>I don't know if my title is right so feel free to edit this post and remove this first paragraph of my post.</p>
  
  <p>I am trying to create a simple API in Laravel and I'm having a problem when i get a paginated shoutouts records to include the users who create it. I have 1 is to 1 relationship between User and Shoutout model and in the tables the shoutouts have the foreign key of user_id since the user is who created the shoutout and not the shoutout created the user.</p>
  
  <p>So I tried to get a collection of shoutouts and include the user associated with it with this method:</p>
  
  <pre><code>$shoutouts = Shoutout::with('user')-&gt;paginate(15); 
  </code></pre>
  
  <p>but I Having this error:</p>
  
  <pre><code>SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.shoutout_id' in 'where clause' (SQL: select * from `users` where `users`.`shoutout_id` in (1))
  </code></pre>
  
  <p>and it looks like the query trying to find shoutout_id to users table and since the foreign key is in the shoutouts table it gets an error in query. If I use this method:</p>
  
  <pre><code>$user = User::with('shoutout')-&gt;paginate(15);
  </code></pre>
  
  <p>there is no problem in querying, but the problem is its now a collection of users not a collection of shoutouts and the shoutout is nested in it, not the user is nested in shoutout collection. Is there a method(function) to use to get what i wanted to happen or a way to do that if if there is no method. I cant find any related question or maybe just my keyword for searching is wrong, feel free to suggest a link here if there is a related question to this question.</p>
  
  <p>edited:
  I think i will use query builder instead, but if there is method to achieve this in Eloquent I will upvote for that</p>