1
I need to make a select in two tables and join them with the union
, until then, but I also need to take the name of the two View
.
I’ve tried using the getTable()
in each select, but it returns me the error:
Non-static method Illuminate\Database\Eloquent\Model::getTable() should not be called statically
I also tried to pick up the select
, because I’ve done it this way once without using the Laravel
: select('tabela1 as table')
and gives me a syntax error.
What’s the right way to do it?
Code:
$first = Lista::where('serie_id', $serie->id)
->select('descricao as result1');
$atividades = Avaliar::where('serie_id', $serie->id)
->select('nota as result1')
->union($first)
->get();
Do you want to get the names of the tables in UNION? I ended up not understanding.?
– novic
Exactly, because I’ll need to identify them in the view.
– Diego Vieira
In the
View
with so??? if speaks the file?– novic
Yes. Simply put, let’s say that the results coming from the list table will be red and those coming from the table will be blue.
– Diego Vieira
I get it @Diego, and if I’m identified in the
SQL
?– novic
I don’t understand, what do you mean?
– Diego Vieira
I can identify in SQL itself the table name explicitly!
– novic
Let’s go continue this discussion in chat.
– novic
Your example there worked well.
– Diego Vieira