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 Pharmaceutic and Pharmaceutic 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 faster in all case -:)

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

    $Galenic= Galenic::Find(1);

    $Medecines= $Galenic->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
2 replies
hachich46's avatar

Hi !

See this :

  1. Pharmaceutic (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');
    

    });

  2. 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.