Hi there.
I think I am not understanding something with Eloquent, and this makes me unable to understand how to create an adequate factory to do a minimum seeding for the app.
Scene
- A campaign has more than one subscriber
- A user can be in more than one campaign

I understand that it is a one-to-many relationship with a pivot table.
Tables
campaing
$table->id();
$table->string('name',100)->nullable(false)->unique();
$table->string('db',100)->nullable(false);
$table->string('table',100)->default('users')->nullable(false);
$table->timestamps();
campaing_subscribers
$table->unsignedBigInteger('campaing_id');
$table->foreign('campaing_id')->references('id')->on('campaings');
$table->unsignedBigInteger('subscriber_id');
$table->foreign('subscriber_id')->references('id')->on('subscribers');
$table->primary(['campaing_id','subscriber_id']);
$table->timestamps();
susbcribers
$table->id();
$table->string('email')->unique();
$table->timestamps();
Models
Campaing
protected $fillable = ['name', 'db', 'table'];
public function subscribers()
{
return $this->belongsToMany(Subscriber::class, 'campaing_subscribers');
}
Subscriber
protected $fillable = ['email'];
public function campaing()
{
return $this->belongsTo(Campaing::class);
}
Campaing_susbcribers
protected $fillable = ['campaings_id', 'subscribers_id'];
Factories
CampaingFactory
{
$campaing = $this->faker->company();
$db = Str::slug($campaing, '_');
return [
'name' => $campaing,
'db' => $db
];
}
SusbcriberFactory
public function definition()
{
return [
'email' => $this->faker->unique()->safeEmail(),
];
}