Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在laravel中获取具有特定角色的用户及其配置文件详细信息_Laravel - Fatal编程技术网

如何在laravel中获取具有特定角色的用户及其配置文件详细信息

如何在laravel中获取具有特定角色的用户及其配置文件详细信息,laravel,Laravel,我试图在laravel中获得具有客户角色的用户以及他们的个人资料详细信息。我的问题是这样的 $customer = User::with(['roles' => function ($query) { $query->where('name', '=', 'customer'); }])->join('profiles', 'profiles.user_id', '=', 'users.id')

我试图在laravel中获得具有客户角色的用户以及他们的个人资料详细信息。我的问题是这样的

    $customer = User::with(['roles' => function ($query) {
                $query->where('name', '=', 'customer');
                }])->join('profiles', 'profiles.user_id', '=', 'users.id')
                ->join('cities', 'cities.id', '=', 'profiles.city')
                ->where([['users.email', 'LIKE', '%'.$email.'%'], ['profiles.mobile', 'LIKE', '%'.$mobile.'%'], ['profiles.name', 'LIKE', '%'.$name.'%'], ['cities.name', 'LIKE', '%'.$city.'%'], ['profiles.home_address', 'LIKE', '%'.$address.'%']])
                ->select('profiles.name','profiles.mobile','profiles.home_address','cities.name as city', 'users.id','users.email')
                ->orderBy($sort_field, $sort_type)
                ->paginate($pagination);
但我得到了所有角色的记录

有人能帮忙或看看这个吗

提前谢谢

下面的代码正在工作

$customer = User::whereHas(
        'roles', function($q){
        $q->where('name', 'customer');
        }
        )->join('profiles', 'profiles.user_id', '=', 'users.id')
            ->join('cities', 'cities.id', '=', 'profiles.city')
            ->where([['users.email', 'LIKE', '%'.$email.'%'], ['profiles.mobile', 'LIKE', '%'.$mobile.'%'], ['profiles.name', 'LIKE', '%'.$name.'%'], ['cities.name', 'LIKE', '%'.$city.'%'], ['profiles.home_address', 'LIKE', '%'.$address.'%']])
            ->select('profiles.name','profiles.mobile','profiles.home_address','cities.name as city', 'users.id','users.email')
            ->orderBy($sort_field, $sort_type)
            ->paginate($pagination);
下面的代码正在运行

$customer = User::whereHas(
        'roles', function($q){
        $q->where('name', 'customer');
        }
        )->join('profiles', 'profiles.user_id', '=', 'users.id')
            ->join('cities', 'cities.id', '=', 'profiles.city')
            ->where([['users.email', 'LIKE', '%'.$email.'%'], ['profiles.mobile', 'LIKE', '%'.$mobile.'%'], ['profiles.name', 'LIKE', '%'.$name.'%'], ['cities.name', 'LIKE', '%'.$city.'%'], ['profiles.home_address', 'LIKE', '%'.$address.'%']])
            ->select('profiles.name','profiles.mobile','profiles.home_address','cities.name as city', 'users.id','users.email')
            ->orderBy($sort_field, $sort_type)
            ->paginate($pagination);

也可以添加db结构是的,在迁移时有一个要点(例如)会很好,或者在第一篇文章中添加它,这样我们就可以在我们的计算机上进行尝试。也可以添加db结构是的,有一个要点(例如)会很好在您的第一篇文章中添加它,以便我们能够在我们的计算机上进行尝试。