私はLaravelを初めて使っています。私はbranch
にcluster_info
に参加したい魅力的なモデルに参加する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
モデルに:
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のブランチテーブルの外部キーを定義できますか? –