条件不符合条件的情况

问题描述 投票:0回答:1
$modules = Role::with(['rights' => function ($q) {
    return $q->with('module');
}])->where('id', $user->role_id)->get();

有人可以帮助解决这个问题吗?

laravel relation
1个回答
1
投票

你不能在with()封闭内部的关系内返回。

相反,你可以使用Nested Eager Loading

$modules = Role::where('id', $user->role_id)
                 ->with('rights.module')
                 ->get();
© www.soinside.com 2019 - 2024. All rights reserved.