Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hachich46's avatar

One table with multiple pivots tables

Hi everyone, these are relations in my models :

Medecine belongsto many Pharmacologic and Pharmacologic belongsto many Medecine
Medecine belongsto many Therapeutic and Therapeutic belongsto many Medecine
Medecine belongsto many Galenic and Galenic belongsto many Medecine
Medecine belongsto many AdministrationMode and AdministrationMode belongsto many Medecine
Medecine belongsto many ActivePrinciple and ActivePrinciple belongsto many Medecine

Pharmaceutic is working well and faster in all case (loadind is normal) -:)

My problem is there, when i execute this type of query in my controller for other relations :

$Pharmacologic = Pharmacologic ::Find(1);

$Medecines= $Pharmacologic ->medecines()->orderBy('field1', 'asc')
->paginate(10);

return view('page', compact('Medecines'));

The view is generating data results witout any error but is STILL LOADING FOR SEVERAL MINUTES. What im missing ?

I think that i was clear

Help me please !

0 likes
1 reply
hachich46's avatar

Migrations

  1. Pharmacologic and medecine pivot Schema::create('pharmaco_medecine', function(Blueprint $table) {

$table->increments('id');

$table->integer('medecine _id')->unsigned(); $table->foreign('medecine _id') ->references('id')->on('tbl_medecine') ->onDelete('cascade');

$table->integer('pharmaco_id')->unsigned(); $table->foreign('pharmaco_id') ->references('id')->on('tbl_pharmaco') ->onDelete('cascade'); });

  1. Therapeutic and medecine pivot

Schema::create('therapeutic_medecine', function(Blueprint $table) {

$table->increments('id');

$table->integer('medecine_id')->unsigned();
$table->foreign('medecine_id')
      ->references('id')->on('tbl_medecine')
      ->onDelete('cascade');
            
$table->integer('therapeutic_id')->unsigned();
$table->foreign('therapeutic_id')
      ->references('id')->on('tbl_therapeutic')
      ->onDelete('cascade');

});

  1. Galenic and medecine pivot

Schema::create('gal_medecine, function(Blueprint $table) {

$table->increments('id');

$table->integer('medecine_id')->unsigned();
$table->foreign('medecine_id')
      ->references('id')->on('tbl_medecine')
      ->onDelete('cascade');
            
$table->integer('gal_id')->unsigned();
$table->foreign('gal_id')
      ->references('id')->on('tbl_gal')
      ->onDelete('cascade');

});

  1. AdministrationMode and medecine pivot

Schema::create('medecine_admin_mode', function(Blueprint $table) {

$table->increments('id');

$table->integer('medecine_id')->unsigned();
$table->foreign('medecine_id')
      ->references('id')->on('tbl_medecine')
      ->onDelete('cascade');
$table->integer('admin_mode_id')->unsigned();
$table->foreign('admin_mode_id')
      ->references('id')->on('tbl_adminmode')
      ->onDelete('cascade');

});

  1. ActivePrinciple and medecine pivot

Schema::create('medecine_active_princip', function(Blueprint $table) {

$table->increments('id');

$table->integer('medecine_id')->unsigned();
$table->foreign('medecine_id')
      ->references('id')->on('tbl_medecine')
      ->onDelete('cascade');
            
$table->integer('active_princip_id')->unsigned();
$table->foreign('active_princip_id')
      ->references('id')->on('tbl_activeprincip')
      ->onDelete('cascade');

});

Please or to participate in this conversation.