5
I have this consultation:
select
Q.id,Q.questao,
D.disciplina,
S.serie,
S.ensino
from questoes as Q
left join capitulos_questoes as CQ
on CQ.questoes_id = Q.id
left join modulos_questoes as MQ
on MQ.questoes_id = Q.id
left join banco_disciplinas as D
on (D.id = CQ.banco_disciplinas_id) or (D.id = MQ.banco_disciplinas_id)
left join banco_series as S
on (S.id = CQ.banco_series_id) or (S.id = MQ.banco_series_id)
I need to paginate the results of this consultation in Laravel 5.2. I am having difficulty in making the consultation with Eloquent because I am using the or
in the LEFT JOIN
.
I tried to do so:
$questoes=\DB::select('select Q.id,Q.questao, D.disciplina, S.serie, S.ensino
from questoes as Q
left join capitulos_questoes as CQ
on CQ.questoes_id = Q.id
left join modulos_questoes as MQ
on MQ.questoes_id = Q.id
LEFT join banco_disciplinas as D
on (D.id = CQ.banco_disciplinas_id) or (D.id = MQ.banco_disciplinas_id)
left join banco_series as S
on (S.id = CQ.banco_series_id) or (S.id = MQ.banco_series_id)')
->paginate(15);
but returns an error saying that it is not possible to paginate an array. How can I resolve?
You can try using the eloquent ORM to simplify your code. You are using the query build. It will make your life easier.
– Miguel Batista
@Miguelbatista, this is my doubt, how to pass this consultation to the eloquent ORM
– Amanda Lima
its syntax that was wrong is
$users = DB::table('users')->paginate(15);
and so on you could ride yourquery builder
normally. I just want to make it clear that my intention is to make the user aware of the errors as a way to help ! example link: https://laravel.com/docs/5.3/pagination– novic