我想使用多个hasMany和belongsTo,其中proposition使用两个函数,一个用于返回注释,另一个用于返回操作如何从hasMany::with(‘proposition ')中检索数据注释
模型命题
public function proposition()
{
return $this-
>belongsTo('App\Proposition','proposition_num_proposition');
}模型操作
public function action() {
return $this->hasMany('App\Action','proposition_num_proposition');
}模型注释
public function notes(){
return $this->hasMany('App\Note','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');在视图中
我想使用laravel elequont从命题where(note.proposition_num_proposition = action.proposition_num_proposition)中检索数据
有什么帮助吗?
发布于 2017-06-16 18:18:17
你试过这样使用它吗?
$actions = Action::with(['proposition', notes])->get();或者,您可以在laravel文档中查看急切加载
如果你使用数组作为输入,应该可以解决你的问题
https://stackoverflow.com/questions/44586725
复制相似问题