Я попытался это:
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 сказал мне, что я не могу применить метод «render» к массиву ...
Так что я думаю, что нужно, чтобы получить Красноречивый Коллекцию вместо ...
Я пробовал некоторые вещи, как это тоже:
$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]: нарушение Cardinality: 1222 Используемые ЗЕЬЕСТ имеют разное количество столбцов (SQL: (выберите COUNT (*) в качестве заполнителя из users
внутреннего соединения employes
на users
. id
= employes
. id_employe
и employes
. id_marchand
= 8) объединение (выберите * от users
внутреннее соединение clients
на users
. id
= clients
. id_client
и clients
.id_marchand
= 8) порядок по seen
возрастанию, created_at
по убыванию)
На другом форуме, парень сказал мне, чтобы просто сделать это в Repository:
return $this->model
->with('role', 'clients', 'employes')
->oldest('seen')
->latest()
->paginate($n);
, а затем играть с некоторым Еогеаспом в вид, как:
@foreach($users->clients as $client)
Но я не мог получить какой-либо результат, и я не знаю, почему ...
Я Trie d некоторые вещи вроде этого: '$ liste_clients = $ this-> model -> with ('clients') -> где ('clients.id_marchand', '=', auth() -> user() - > id) -> где ('users.id', '=', 'clients.id_client'); $ liste_employes = $ this-> модель -> с ('') Employés -> где ('employes.id_marchand', '=', Auth() -> пользователя() -> ид) -> где ('users.id', '=', 'employes.id_employe') -> union ($ liste_clients); возвращение $ liste_employes -> старый ('видел') -> последняя() -> постраничной ($ п); ' , но моя самая большая проблема в том, что я не в состоянии выбрать из нескольких таблиц с построитель запросов , –