这些是我模特中的关系:
药理学在所有情况下运作良好且速度更快(loadind是正常的) - :)
当我在我的控制器中为其他关系执行此类查询时,我的问题就在那里:
$Pharmacologic = Pharmacologic ::Find(1);
$Medecines= $Pharmacologic ->medecines()->orderBy('field1', 'asc')
->paginate(10);
return view('page', compact('Medecines'));
迁移
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'); });
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');
});
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');
});
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');
});
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');
});
该视图生成的数据结果没有任何错误,但仍然几乎可以加载几分钟。我失踪了什么?
Thnx并抱歉这篇长篇文章
模型
MEDECINE
class Medecine extends Model
{
protected $table='tbl_medecine';
public function pharmacologics()
{
return $this->belongsToMany('App\Pharmacologic');
}
public function therapeutics()
{
return $this->belongsToMany('App\Therapeutic');
}
public function galenics()
{
return $this->belongsToMany('App\Galenic');
}
public function administrationmodes()
{
return $this->belongsToMany('App\AdministrationMode');
}
public function activeprinciples()
{
return $this->belongsToMany('App\ActivePrinciple');
}
}
药理学
class Pharmacologic extends Model
{
//
protected $table='tbl_pharmacologic';
public function medecines()
{
return $this->belongsToMany('App\Medecine');
}
}
等等......