我已经试过这样:
return DB::select(DB::raw('select users.* from clients, users where clients.id_marchand = 8 and users.id = clients.id_client union select users.* from employes, users where employes.id_marchand = 8 and users.id = employes.id_employe order by `seen` asc, `created_at` desc limit 25 offset 0'), [1]);
但在UserController.php,我有:
public function indexSort($role)
{
$counts = $this->user_gestion->counts();
$users = $this->user_gestion->index(25, $role);
$links = $users->render();
$roles = $this->role_gestion->all();
return view('back.users.index', compact('users', 'links', 'counts', 'roles'));
}
Laravel告诉我,我无法将“渲染”方法应用于阵列...
所以我觉得我需要一个雄辩的集合,而不是...
我已经尝试了一些这样的事情太:
$liste_clients = $this->model
->with('clients')
->where('clients.id_marchand', '=', auth()->user()->id)
->where('users.id', '=', 'clients.id_client');
$liste_employes = $this->model
->with('employes')
->where('employes.id_marchand', '=', auth()->user()->id)
->where('users.id', '=', 'employes.id_employe')
->union($liste_clients);
return $liste_employes
->oldest('seen')
->latest()
->paginate($n);
,但我最大的问题是,我无法从中选择查询生成器的几个表。
即使加入:
$liste_clients = $this->model
->join('clients', function ($join) {
$join->on('users.id', '=', 'clients.id_client')
->where('clients.id_marchand', '=', auth()->user()->id);
});
$liste_employes = $this->model
->join('employes', function ($join) {
$join->on('users.id', '=', 'employes.id_employe')
->where('employes.id_marchand', '=', auth()->user()->id);
})
->union($liste_clients);
return $liste_employes
->oldest('seen')
->latest()
->paginate($n);
我得到一个错误信息:
SQLSTATE [21000]:基数违规:1222条使用的SELECT语句具有不同的列数(SQL:(从users
内上users
加入employes
SELECT COUNT(*)作为骨料。id
= employes
。id_employe
和employes
。id_marchand
= 8)联合(SELECT * FROM内部加入clients
users
。 id
= clients
。 id_client
和clients
。id_marchand
= 8)seen
递增,created_at
DESC)
上的其他论坛秩序,一个人告诉我简单地做这在Repository:
return $this->model
->with('role', 'clients', 'employes')
->oldest('seen')
->latest()
->paginate($n);
,然后用一些的foreach在玩的观点,如:
@foreach($users->clients as $client)
但我无法得到任何结果,我不知道为什么...
我已经特里('clients') - > where('clients.id_marchand','=',auth() - > user() - 这是一个类似于这样的事情: '$ liste_clients = $ this-> model - > > id) - > where('users.id','=','clients.id_client'); $ liste_employes = $ this-> model - > with('employes') - > where('employes.id_marchand','=',auth() - > user() - > id) - > where ('users.id','=','employes.id_employe') - > union($ liste_clients); 返回$ liste_employes - >最古老( '看到') - >最新的() - > PAGINATE($ N);' 但我最大的问题是,我无法从查询生成器几个表选择。 –