0
I need to search the data of a table of processes, and of other 2 tables one of authors and defendants of the process, the doubt is how to search in grouped form that I can go through with foreach to fill a report, I am using the Laravel, list of tables and how it should look in the report.
$processos = Processo::join('autores', 'autores.processo_id', 'processos.id')
->join('reus', 'reus.processo_id', 'processos.id')
->join('pessoas', 'autores.pessoa_id', 'pessoas.id')
->join('pessoas', 'reus.pessoa_id', 'pessoas.id')
->select('pessoas.nome as nome_pessoa', 'processos.*', 'autores.*', 'reus.*')->get();
Of that mistake: SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: pessoas (SQL: select pessoas.nome as nome_pessoa, processos.*, autores.*, reus.* from processos inner join autores on processo.processo_id = processos.id inner join reus_processo on reus.processo_id = processos.id inner join pessoas on autores.pessoa_id = pessoas.id inner join pessoas on reus.pessoa_id = pessoas.id)
Put the class code too.
– Andre Gusmao
What class? you say the controller?
– Carlos Eduardo Silva
No, your model classes:
Processo
,Pessoas
,Reus
andAutores
– Andre Gusmao
Your table has a date, but your bank model doesn’t! Maybe you need to load the information and then unite it according to a criterion, only bank result in these relationships seems to me quite complicated, at least I think...
– novic
Using the Laravel ORM concepts you can achieve the goal. See this example. https://github.com/GeekSilva97/laravel-orm
– GeekSilva