我是新来的Laravel。 这里是我的架构:雄辩Laravel加入模型5.3
Schema::create('cluster_info', function (Blueprint $table) {
$table->increments('id');
$table->string('code')->unique();
$table->string('pa_lastname');
$table->string('pa_firstname');
$table->string('pa_middlename');
$table->string('pa_suffix');
$table->integer('branch_id');
$table->timestamps();
});
Schema::create('cluster_grouping', function (Blueprint $table) {
$table->increments('id');
$table->integer('cluster_id');
$table->integer('client_id');
$table->timestamps();
});
Schema::create('branch', function (Blueprint $table) {
$table->increments('id');
$table->string('code')->unique();
$table->string('name');
$table->string('region');
$table->timestamps();
});
我想加入cluster_info
到branch
。所以在我的Cluster_Info
型号:
public function Branches(){
return $this->hasOne('App\Branch');
}
,当我把它在我的控制有null
值
$cluster = new App\Cluster_Info;
dd($cluster->Branches());
什么是在''branch'你cluster_info'外键? – Tiger
在cluster_info表的分支表中定义外键。 –
@BalrajAllam如何在clusteri_info中定义分支表的外键? –