我有一个严重的问题。
我有3个型号
好榜样:
<?php
class Role extends Eloquent{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'roles';
public function users()
{
return $this->belongsToMany('User', 'user_roles');
}
}
Run Code Online (Sandbox Code Playgroud)
用户模型:
public function roles()
{
return $this->belongsToMany('Role', 'user_roles');
}
Run Code Online (Sandbox Code Playgroud)
现在,在我的控制器中,我正在按选定的角色来吸引用户,或者如果未选中,则在与所有角色相关的所有用户:
$roles = Role::with([
'users' => function($query) use ($memtype)
{
$query->where('users.membertype', $memtype);
$query->orderBy('users.name');
$query->paginate(10);
}
])->where('id', $role_id)->get();
Run Code Online (Sandbox Code Playgroud)
如果我不想按角色过滤,则使用以下代码:
$roles = Role::with([
'users' => function($query) use ($memtype)
{
$query->where('users.membertype', $memtype);
$query->orderBy('users.name');
$query->paginate(10);
}
])->get();
Run Code Online (Sandbox Code Playgroud)
在我看来
我正在尝试通过以下代码生成分页链接,
@foreach($roles …Run Code Online (Sandbox Code Playgroud) 我试过以下行
appraiser_email = auth_user.objects.get(id__exact=2)
Run Code Online (Sandbox Code Playgroud)
当我在线上执行时,它说
global name 'auth_user' is not defined
Run Code Online (Sandbox Code Playgroud)
我想在models.py中定义模型auth_user还是有其他方法吗?
提前致谢
元组,列表和字典如何存储在python的后端?为什么我们不能在分配后改变元组?它在后台如何工作?