laravel - laravel 在枢轴上具有多个模型关系
问题描述
我有一个州、县、销售团队和用户模型。
销售团队.php
public function state(){
return $this->belongsTo(State::class);
}
public function manager(){
return $this->belongsTo(User::class,'manager_id');
}
状态.php
public function counties(){
return $this->hasMany('App\County')->orderBy('county');
}
县城.php
我想要实现的是,在某些情况下,可能会有一个子经理分配给一个销售团队,但只分配给一个特定的县。我创建了一个这样的表(我相信我需要它,如果我不这样做,请纠正我):
Schema::create('sub_managers', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('salesteam_id');
$table->unsignedBigInteger('state_id');
$table->unsignedBigInteger('submanager_id');
$table->timestamps();
});
我如何与这种类型的关系互动?我以为我需要这张桌子,因为它很有意义,但现在我不知道如何与它联系起来,我也必须制作模型吗?如果是这样,我如何将县与子经理联系起来以考虑分配给它的销售团队?
解决方案
推荐阅读
- oracle - 在 oracle / 学说中转换类似函数的问题
- database - Key/Value 数据库的二级索引
- python - keras 与 TensorFlow GPU、CUDA_ERROR_LAUNCH_FAILED 超参数搜索
- google-cloud-platform - terraform资源块中不同块内的条件流
- ios - 无法在 iOS 错误代码 70 上构建项目,如何解决?
- azure - 在 Azure IoT Edge 上查看 MPU6050 数据
- matrix - 如何在 JULIA 中有效地构造以下形式的块矩阵?
- vb.net - 在VB .Net中的子字符串之前修剪字符串
- neo4j - 如何使用 Neo4J Cypher 查询生成器?
- php - 如何在mysql php中的外键列上允许null?