title: BadMethodCallException: Call to undefined method in database seeder in Laravel 8
body: <p>I have errors executing the command::</p>
  <pre><code>&gt;php artisan migrate:refresh --seed
  </code></pre>
  <p>The error message is:</p>
  <pre><code> BadMethodCallException
  
    Call to undefined method App\Models\Diary::diarySubjob()
  
    at C:\MAMP\htdocs\dominios\vendor\laravel\framework\src\Illuminate\Support\Traits\ForwardsCalls.php:50
       46▕      * @throws \BadMethodCallException
       47▕      */
       48▕     protected static function throwBadMethodCallException($method)
       49▕     {
    ➜  50▕         throw new BadMethodCallException(sprintf(
       51▕             'Call to undefined method %s::%s()', static::class, $method
       52▕         ));
       53▕     }
       54▕ }
  
    • Bad Method Call: Did you mean App\Models\Diary::subjobs() ?
  
    1   C:\MAMP\htdocs\dominios\vendor\laravel\framework\src\Illuminate\Support\Traits\ForwardsCalls.php:36
        Illuminate\Database\Eloquent\Model::throwBadMethodCallException()
  
    2   C:\MAMP\htdocs\dominios\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php:1993
        Illuminate\Database\Eloquent\Model::forwardCallTo()
  </code></pre>
  <p><strong>Class DiarySubJob</strong></p>
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Factories\HasFactory;
  use Illuminate\Database\Eloquent\Relations\Pivot;
  
  class DiarySubjob extends Pivot
  {
      use HasFactory;
  
      /**
       * The attributes that are mass assignable.
       *
       * @var array
       */
      protected $fillable = [
          'diary_id',
          'work_id',
          'subjob_id',
          'company',
          'customer',
          'repair',
          'duration',
          'observations',
      ];
  
      /**
       * Indicates if the IDs are auto-incrementing.
       *
       * @var bool
       */
      public $incrementing = true;
  
      
      /** 
       * Partidas de un diario.
       */
      public function subjobs()
      {
          $this-&gt;belongsTo(Subjob::class);
      }
  
  
      /**
       * Diarios de una partida.
       */
      public function diaries()
      {
          $this-&gt;belongsTo(Diary::class);
      }
  
      /**
       * Obras o clientes de una partida.
       */
      public function works()
      {
          $this-&gt;belongsTo(Work::class);
      }
  }
  </code></pre>
  <p><strong>Class Diary</strong></p>
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Factories\HasFactory;
  use Illuminate\Database\Eloquent\Model;
  
  class Diary extends Model
  {
      use HasFactory;
  
      /**
       * The attributes that are mass assignable.
       *
       * @var array
       */
      protected $fillable = [
          'user_id',
          'observations',
          'duration',
          'overtime'
      ];
  
      /**
       * The attributes that should be cast to native types.
       *
       * @var array
       */
      protected $casts = [
          'observations'  =&gt; 'string',
      ];
  
      /**
       * Obtener el usuario/empleado de un diario.
       */ 
      public function user()
      {
          return $this-&gt;belongsTo(User::class);
      }
  
      /** 
       * Obtener las partidas de un parte diario.
       */
      public function subjobs()
      {
          return $this-&gt;belongsToMany(Subjob::class)-&gt;using(DiarySubjob::class);
      }
  }
  </code></pre>
  <p><strong>Class Subjob</strong></p>
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Factories\HasFactory;
  use Illuminate\Database\Eloquent\Model;
  
  class Subjob extends Model
  {
      use HasFactory;
  
      /**
       * The attributes that are mass assignable.
       *
       * @var array
       */
      protected $fillable = [
          'job_id',
          'name'
      ];
  
      /**
       * The attributes that should be cast to native types.
       *
       * @var array
       */
      protected $casts = [
          'name'      =&gt; 'string'
      ];
  
      /** 
       * Obtener el trabajo/partida al que pertenece este subtrabajo/subpartida.
       */
      public function job()
      {
          $this-&gt;hasMany(Job::class);
      }
  
      /**
       * Partes de trabajo diarios de la partida.
       */
      public function diaries()
      {
          $this-&gt;belogsToMany(Diary::class)-&gt;using(DiarySubjob::class);
      }
  }
  
  </code></pre>
  <p><strong>Class DiarySubjobFactory</strong></p>
  <pre><code>&lt;?php
  
  namespace Database\Factories;
  
  use App\Models\DiarySubjob;
  use App\Models\Diary;
  use App\Models\Subjob;
  use App\Models\Work;
  use Illuminate\Database\Eloquent\Factories\Factory;
  
  class DiarySubjobFactory extends Factory
  {
      /**
       * The name of the factory's corresponding model.
       *
       * @var string
       */
      protected $model = DiarySubjob::class;
  
      /**
       * Define the model's default state.
       *
       * @return array
       */
      public function definition()
      {
          return [
              'diary_id' =&gt; DiarySubjob::diaries()-&gt;all()-&gt;random()-&gt;id,
              'work_id' =&gt; Work::all()-&gt;random()-&gt;id,
              'subjob_id' =&gt; Subjob::all()-&gt;random()-&gt;id,            
              'company' =&gt; $this-&gt;faker-&gt;company(),
              'repair' =&gt; $this-&gt;faker-&gt;boolean(),
              'duration' =&gt; '02:00:00',
              'overtime' =&gt; '00:00:00',
              'observations' =&gt; $this-&gt;faker-&gt;realText(255, 2)
          ];
      }
  }
  
  </code></pre>
  <p><strong>Class DatabaseSeeder</strong></p>
  <pre><code>&lt;?php
  
  namespace Database\Seeders;
  
  use Illuminate\Database\Seeder;
  
  class DatabaseSeeder extends Seeder
  {
      /**
       * Seed the application's database.
       *
       * @return void
       */
      public function run()
      {
          \App\Models\Work::factory(5)-&gt;create();
  
          $this-&gt;call([
              JobSeeder::class,
              SubJobSeeder::class,
              ConfigurationSeeder::class
          ]);
  
          \App\Models\User::factory(20)
              -&gt;has(\App\Models\Salary::factory(1))
              -&gt;has(\App\Models\Diary::factory(10))            
              -&gt;create();
  
          \App\Models\Diary::factory(1)
              -&gt;has(\App\Models\DiarySubjob::factory(15))
              -&gt;create();
      }
  }
  
  </code></pre>
  <p>The error when this line is executed:</p>
  <pre><code>\App\Models\Diary::factory(1)
              -&gt;has(\App\Models\DiarySubjob::factory(15))
              -&gt;create();
  </code></pre>
  <p>To be more concise, I get the error running this:</p>
  <pre><code>-&gt;has(\App\Models\DiarySubjob::factory(15))
  </code></pre>
  <p>It tells me that I am calling a method that is not defined <strong>App\Models\Diary::diarySubjob()</strong> and it advises me to call the method <strong>App\Models\Diary::subjobs()</strong> But nowhere do I call the method <strong>App\Models\Diary::diarySubjob()</strong></p>
  <p>What can this error be due to? I am very lost. Any suggestion?</p>