拉拉维尔与 3 表的关系使用雄辩

  • 本文关键字:关系 laravel-5
  • 更新时间 :
  • 英文 :


我想使用多个hasMany和属于该命题使用两个函数,一个用于返回笔记,另一个用于返回操作如何从操作中检索数据注释::with('命题'(

模型命题

      public function proposition()
     {
      return $this-
           >belongsTo('AppProposition','proposition_num_proposition');
     }

模型操作

       public function action() {
    return $this->hasMany('AppAction','proposition_num_proposition');
      }

型号说明

     public function notes(){
    return $this->hasMany('AppNote','proposition_num_proposition');
    }

和桌子

命题

num_proposition命题

行动

id_action行动prposition_num_proposition

注意

id_note注意proposition_num_proposition

在控制器中

   $actions = Action::all();
   $propositions = Proposition::with('actions');
    $notes = Note::all();
    $propositions2 = Proposition::with('notes');

在视图中

我想从命题中检索数据,其中(note.proposition_num_proposition = action.proposition_num_proposition(使用拉拉维尔·

请帮忙吗?

你有没有试过这样使用它

$actions = Action::with(['proposition', notes])->get();

或者您可以在 laravel 文档中查看急切加载

如果你使用数组作为输入,应该可以解决你的问题

最新更新