0
私はLaravel BackPack CRUDを使用しています。 PERSONNEが構造の一方構造 LaravelのバックパックのOne To Many(1-N)の関係
- :私は2つのテーブル間の1-N(多対一)関係を有します
だから私は人を持ってテーブル:
idPersonnes、名前、ファーストネーム、idStructures
そして構造テーブル:
idStructures、名前、私は私のPERSONNEモデルで住所
:私のPERSONNEで
public function structure() { return $this->belongsTo('App\Models\Structure', 'idStructures', 'idStructures'); }
コントローラーiは:
$this->crud->addField([ 'label' => 'Structure', 'type' => 'select2', 'name' => 'idStructures', // the db column for the foreign key 'entity' => 'structure', // the method that defines the relationship in your Model 'attribute' => 'nom', // foreign key attribute that is shown to user 'model' => 'App\Models\Structure' // foreign key model ]);
これはうまくいきます。私はpersonneを編集するときにselect2ドロップダウンがあり、構造を選択して保存することができます。
私は構造を編集するときに、その構造に属するすべてのpersonnesを表示したいと思います。私は持っている私の構造モデルで :私の構造制御装置において
public function personnes() { return $this->hasMany('App\Models\Personne', 'idStructures', 'idStructures'); }
私が持っている:
$this->crud->addField([ 'label' => 'Personnes', 'type' => 'select2', 'name' => 'idStructures', // the db column for the foreign key 'entity' => 'personnes', // the method that defines the relationship in your Model 'attribute' => 'nom', // foreign key attribute that is shown to user 'model' => 'App\Models\Personne' // foreign key model ]);
それは働いていません。 何か間違っていますか? ご協力いただきありがとうございます。