FilamentF
Filament2y ago
taz

Unconventional Pivot table name. How to tell the Relation manager to use this table name ?

I have a many to many relationship between my Customer Model and Chatter Model and a Pivot class unconventionaly named ChattingInstance. I created a RelationManager for the CustomerResource named ChattersRelationManager but the DB request failed because it tries to use the conventional table name for the Pivot class which should be name chatter_customer. How I can force to use the right table name which is 'chatting_instances' ?

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb.chatter_customer' doesn't exist


class ChattingInstance extends Pivot {
   protected $table = 'chatting_instances';
}

class Customer extends Model {
  public function chatters(): BelongsToMany
      {
          return $this->belongsToMany(Chatter::class)
              ->withPivot('url', 'status')
              ->withTimestamps()
              ->using(ChattingInstance::class);
      }
}

class Chatter extends Model {
   public function customers(): BelongsToMany
      {
          return $this->belongsToMany(Customer::class)
              ->withPivot('url', 'status')
              ->withTimestamps()
              ->using(ChattingInstance::class);
      }
}
Was this page helpful?