admin
テーブルがあり、admin
には多くのform
があります。各form
は、ダッシュボードに表示されるadmin
に割り当てられます。Laravel - カスタムでない行を取得する.Many関係
form
はadmin
に割り当てられていない可能性があります。
すべて入手したいforms
何か助けていただければ幸いです。ありがとうございました!
編集:説明したようAdmin
がカスタム関係を経由してform
に関連しているHere
、
Admin.php
public function states(){
return $this->belongsToMany('App\State');
}
public function cities()
{
return $this->belongsToMany('App\City');
}
//gets the forms in this admin's city or state
//Let me know if there is a better way to do this, i feel like im overdoing stuff here
public function forms()
{
//cities
$cities = $this->cities->pluck('name');
//states
$states = $this->states->pluck('name');
$users = User::whereIn('state',$states)>orWhereIn('city',$cities)->get()->pluck('id');
$forms = Form::whereIn('user_id',$users);
return $forms;
}
を要約するためのIDという形式を取得したいですdoesntはanyに属しますadmin
基本的に、その関係の逆数をフォームモデルで定義する必要があります。 –
私はコードを追加しました。あなたは正しい方向に向けることができますか? –