title: Laravel: Custom Foreign Key in One-To-Many Relationship Does Not Resolve
body: <p>There are two Models <strong>User</strong> and <strong>Submission</strong> and a User can have any number of submissions in which he is referenced as <em>Author</em>. I have set up the relationship according to the <a href="https://laravel.com/docs/7.x/eloquent-relationships#one-to-many" rel="nofollow noreferrer">documentation</a> and
  the result of <code>hasMany()</code> is working fine. Only the <code>belongsTo()</code> method does not return the expected objects.</p>
  <p>Here is the migration of my models:</p>
  <pre><code>Schema::create('users', function (Blueprint $table) {
      $table-&gt;id();
  });
  
  Schema::create('submissions', function (Blueprint $table) {
      $table-&gt;id();
      $table-&gt;foreignId( 'author' );
      $table-&gt;foreign( 'author' )-&gt;references('id')-&gt;on('users');
  });
  </code></pre>
  <p>And these are the relationships within my models:</p>
  <pre><code>class User extends Authenticatable {
      public function submissions() {
          return $this-&gt;hasMany( 'App\Submission', 'author' );
      }
  }
  
  class Submission extends Model {
      public function author() {
          return $this-&gt;belongsTo( 'App\User', 'author' );
      }
  }
  </code></pre>
  <p>Now, in my controller I want to execute this code:</p>
  <pre><code>$author = Submission::find(1)-&gt;author;
  dd($author);
  </code></pre>
  <p>But, instead of the user object, the stored integer value of the author ID is printed. The relationship does not seem to be resolved via the <code>author()</code> method.
  On the other hand, when I fetch a user and their submissions, everything works as expected, i.e. the submissions are printed as objects:</p>
  <pre><code>$u = User::find(1)-&gt;submissions;
  dd($u);
  </code></pre>
  <p>But the relation from Submission to User <em>does</em> get resolved properly, when I do <em>not</em> define a custom foreign key with <code>belongsTo</code> and rename the colum to <code>author_id</code>.</p>
  <p>The configuration that works is this one:</p>
  <pre><code>//migration for Submissions table
  Schema::create('submissions', function (Blueprint $table) {
      $table-&gt;id();
      $table-&gt;foreignId( 'author_id' );
      $table-&gt;foreign( 'author_id' )-&gt;references('id')-&gt;on('users');
  });
  
  //within Submission model
  public function author() {
      return $this-&gt;belongsTo( 'App\User' );
  }
  </code></pre>
  <p>I have the feeling that I'm missing something. Is there any additional link I have to make? I browsed through the documentation and the web for solutions, but to no success. If there is no other solution, I'll follow with renaming the column. But I'd rather understand the cause of my problem and work with my original design.</p>