Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel连接表以从每个表中获取属性_Php_Sql_Laravel_Eloquent - Fatal编程技术网

Php Laravel连接表以从每个表中获取属性

Php Laravel连接表以从每个表中获取属性,php,sql,laravel,eloquent,Php,Sql,Laravel,Eloquent,我有三张桌子: warehouses: id | warehouse_name 我正在尝试获取大量记录,并希望在视图中显示这些记录,如下所示: good_name | warehouse_name | quantity | 什么是正确的查询,以获得这个结果与雄辩 好的车型 class Good extends Model { /** * Get the Good Quantity for this Good. */ public function good_quantities(

我有三张桌子:

warehouses: id | warehouse_name 


我正在尝试获取大量记录,并希望在视图中显示这些记录,如下所示:

good_name | warehouse_name | quantity |
什么是正确的查询,以获得这个结果与雄辩

好的车型

class Good extends Model
{

/**
 * Get the Good Quantity for this Good.
 */
public function good_quantities()
{
    return $this->hasMany('App\Models\Good_Quantity','good_id');
}

}
class Warehouse extends Model
{
/**
 * Get the Goods Quantity for this Warehouse.
 */
public function good_quantities()
{
    return $this->hasMany('App\Models\Good_Quantity','warehouse_id');
}

}
class Good_Quantity extends Model
{

/**
 * Get the Good's Info.
 */
public function good()
{
    return $this->belongsTo('App\Models\Good','good_id');
}

/**
 * Get the Good Quantity's Warehouse.
 */
public function warehouse()
{
    return $this->belongsTo('App\Models\Warehouse','warehouse_id');
}

}
仓库模型

class Good extends Model
{

/**
 * Get the Good Quantity for this Good.
 */
public function good_quantities()
{
    return $this->hasMany('App\Models\Good_Quantity','good_id');
}

}
class Warehouse extends Model
{
/**
 * Get the Goods Quantity for this Warehouse.
 */
public function good_quantities()
{
    return $this->hasMany('App\Models\Good_Quantity','warehouse_id');
}

}
class Good_Quantity extends Model
{

/**
 * Get the Good's Info.
 */
public function good()
{
    return $this->belongsTo('App\Models\Good','good_id');
}

/**
 * Get the Good Quantity's Warehouse.
 */
public function warehouse()
{
    return $this->belongsTo('App\Models\Warehouse','warehouse_id');
}

}
好的数量模型

class Good extends Model
{

/**
 * Get the Good Quantity for this Good.
 */
public function good_quantities()
{
    return $this->hasMany('App\Models\Good_Quantity','good_id');
}

}
class Warehouse extends Model
{
/**
 * Get the Goods Quantity for this Warehouse.
 */
public function good_quantities()
{
    return $this->hasMany('App\Models\Good_Quantity','warehouse_id');
}

}
class Good_Quantity extends Model
{

/**
 * Get the Good's Info.
 */
public function good()
{
    return $this->belongsTo('App\Models\Good','good_id');
}

/**
 * Get the Good Quantity's Warehouse.
 */
public function warehouse()
{
    return $this->belongsTo('App\Models\Warehouse','warehouse_id');
}

}


首先,您可以将BelongToMany用于仓库和货物学习多对多关系: